Skip to content

Commit 9579514

Browse files
committed
Make .info more uniform throughout all classes that have it
1 parent f382bec commit 9579514

10 files changed

Lines changed: 58 additions & 56 deletions

File tree

src/blosc2/b2view/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ def object_metadata(obj: Any) -> dict[str, Any]:
341341
return dict(obj.info_items)
342342
except Exception:
343343
return {
344-
"rows": getattr(obj, "nrows", len(obj)),
345-
"columns": getattr(obj, "ncols", len(getattr(obj, "col_names", []))),
344+
"nrows": getattr(obj, "nrows", len(obj)),
345+
"ncols": getattr(obj, "ncols", len(getattr(obj, "col_names", []))),
346346
"schema": {
347347
name: str(getattr(obj[name], "dtype", None)) for name in getattr(obj, "col_names", [])
348348
},

src/blosc2/batch_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def info_items(self) -> list:
948948
("nitems", sum(batch_sizes)),
949949
("nbytes", format_nbytes_info(self.nbytes)),
950950
("cbytes", format_nbytes_info(self.cbytes)),
951-
("cratio", f"{self.cratio:.2f}"),
951+
("cratio", f"{self.cratio:.2f}x"),
952952
("cparams", self.cparams),
953953
("dparams", self.dparams),
954954
]

src/blosc2/c2array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def info_items(self) -> list:
477477
items += [("dtype", self.dtype)]
478478
items += [("nbytes", format_nbytes_info(self.nbytes))]
479479
items += [("cbytes", format_nbytes_info(self.cbytes))]
480-
items += [("cratio", f"{self.cratio:.2f}")]
480+
items += [("cratio", f"{self.cratio:.2f}x")]
481481
items += [("cparams", self.cparams)]
482482
# items += [("dparams", self.dparams)]
483483
return items

src/blosc2/ctable.py

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,33 +1207,41 @@ def info_items(self) -> list[tuple[str, object]]:
12071207
spec = col_meta.spec if col_meta is not None else None
12081208
chunks = getattr(raw, "chunks", None)
12091209
blocks = getattr(raw, "blocks", None)
1210+
1211+
if self.is_list:
1212+
backend = "list"
1213+
elif self.is_varlen_scalar:
1214+
backend = "variable-length scalar"
1215+
elif self.is_dictionary:
1216+
backend = "dictionary"
1217+
else:
1218+
backend = "NDArray" if isinstance(raw, blosc2.NDArray) else type(raw).__name__
1219+
1220+
# Virtual computed columns are not stored; otherwise report the table's
1221+
# storage kind, mirroring CTable.info's persistent/in-memory wording.
1222+
if self.is_computed:
1223+
storage = "computed"
1224+
elif isinstance(table._storage, FileTableStorage):
1225+
storage = "persistent"
1226+
else:
1227+
storage = "in-memory"
1228+
1229+
# Block order mirrors CTable.info: identity, shape/grid, sizes, content,
1230+
# then compression params.
12101231
items: list[tuple[str, object]] = [
12111232
("type", self.__class__.__name__),
12121233
("name", self._col_name),
1213-
("nrows", len(self)),
1214-
("shape", self.shape),
1234+
("dtype", table._dtype_info_label(self.dtype, spec)),
1235+
("backend", backend),
1236+
("storage", storage),
12151237
]
1238+
1239+
items.append(("nrows", len(self)))
1240+
items.append(("shape", self.shape))
12161241
if chunks is not None:
12171242
items.append(("chunks", chunks))
12181243
if blocks is not None:
12191244
items.append(("blocks", blocks))
1220-
items.extend(
1221-
[
1222-
("dtype", table._dtype_info_label(self.dtype, spec)),
1223-
("computed", self.is_computed),
1224-
("nullable", self.null_value is not None or getattr(spec, "nullable", False)),
1225-
]
1226-
)
1227-
1228-
if self.is_list:
1229-
items.append(("storage", "list"))
1230-
elif self.is_varlen_scalar:
1231-
items.append(("storage", "variable-length scalar"))
1232-
elif self.is_dictionary:
1233-
items.append(("storage", "dictionary"))
1234-
items.append(("dictionary_size", len(raw.dictionary)))
1235-
else:
1236-
items.append(("storage", "ndarray" if isinstance(raw, blosc2.NDArray) else type(raw).__name__))
12371245

12381246
nbytes = getattr(raw, "nbytes", None)
12391247
cbytes = getattr(raw, "cbytes", None)
@@ -1243,11 +1251,12 @@ def info_items(self) -> list[tuple[str, object]]:
12431251
if cbytes is not None:
12441252
items.append(("cbytes", format_nbytes_info(cbytes)))
12451253
if cratio is not None:
1246-
items.append(("cratio", f"{cratio:.2f}"))
1254+
items.append(("cratio", f"{cratio:.2f}x"))
1255+
1256+
items.append(("nullable", self.null_value is not None or getattr(spec, "nullable", False)))
1257+
if self.is_dictionary:
1258+
items.append(("dictionary_size", len(raw.dictionary)))
12471259

1248-
urlpath = getattr(raw, "urlpath", None)
1249-
if urlpath is not None:
1250-
items.append(("urlpath", urlpath))
12511260
cparams = getattr(raw, "cparams", None)
12521261
dparams = getattr(raw, "dparams", None)
12531262
if cparams is not None:
@@ -2568,7 +2577,7 @@ def info_items(self) -> list[tuple[str, object]]:
25682577
("nrows", self.nrows),
25692578
("nbytes", format_nbytes_info(self.nbytes)),
25702579
("cbytes", format_nbytes_info(self.cbytes)),
2571-
("cratio", f"{self.cratio:.1f}x"),
2580+
("cratio", f"{self.cratio:.2f}x"),
25722581
("schema", schema_summary),
25732582
]
25742583

@@ -9303,17 +9312,15 @@ def info_items(self) -> list[tuple[str, object]]:
93039312
items = [
93049313
("type", self.__class__.__name__),
93059314
("storage", storage_type),
9306-
("rows", self.nrows),
9307-
("columns", self.ncols),
93089315
("view", self.base is not None),
9316+
("nrows", self.nrows),
9317+
("ncols", self.ncols),
9318+
("chunks", self.chunks if self.chunks is not None else "none (no fixed-size columns)"),
9319+
("blocks", self.blocks if self.blocks is not None else "none (no fixed-size columns)"),
93099320
("nbytes", format_nbytes_info(self.nbytes)),
93109321
("cbytes", format_nbytes_info(self.cbytes)),
9311-
("cratio", f"{self.cratio:.1f}x"),
9322+
("cratio", f"{self.cratio:.2f}x"),
93129323
("schema", schema_summary),
9313-
(
9314-
"valid_rows_mask",
9315-
f"cbytes={format_nbytes_info(self._valid_rows.cbytes)}",
9316-
),
93179324
("indexes", index_summary if index_summary else "none"),
93189325
]
93199326
if urlpath is not None:

src/blosc2/list_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def info_items(self) -> list:
649649
("pending_rows", len(self._pending_cells) if self.spec.storage == "batch" else 0),
650650
("nbytes", format_nbytes_info(self.nbytes)),
651651
("cbytes", format_nbytes_info(self.cbytes)),
652-
("cratio", f"{self.cratio:.2f}"),
652+
("cratio", f"{self.cratio:.2f}x"),
653653
]
654654

655655
def to_cframe(self) -> bytes:

src/blosc2/ndarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,7 +3935,7 @@ def info(self) -> InfoReporter:
39353935
chunks : (10,)
39363936
blocks : (10,)
39373937
dtype : int64
3938-
cratio : 0.73
3938+
cratio : 0.73x
39393939
cparams : {'blocksize': 80,
39403940
'clevel': 1,
39413941
'codec': <Codec.ZSTD: 5>,
@@ -3968,7 +3968,7 @@ def info_items(self) -> list:
39683968
items += [("dtype", self.dtype)]
39693969
items += [("nbytes", format_nbytes_info(self.nbytes))]
39703970
items += [("cbytes", format_nbytes_info(self.cbytes))]
3971-
items += [("cratio", f"{self.cratio:.2f}")]
3971+
items += [("cratio", f"{self.cratio:.2f}x")]
39723972
items += [("cparams", self.cparams)]
39733973
items += [("dparams", self.dparams)]
39743974
return items

src/blosc2/objectarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def info_items(self) -> list:
384384
("chunk_cbytes_avg", f"{avg_chunk_cbytes:.2f}"),
385385
("nbytes", format_nbytes_info(self.nbytes)),
386386
("cbytes", format_nbytes_info(self.cbytes)),
387-
("cratio", f"{self.cratio:.2f}"),
387+
("cratio", f"{self.cratio:.2f}x"),
388388
("cparams", self.cparams),
389389
("dparams", self.dparams),
390390
]

src/blosc2/schunk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def info(self) -> InfoReporter:
535535
typesize : 1
536536
nbytes : 24000
537537
cbytes : 82
538-
cratio : 292.68
538+
cratio : 292.68x
539539
cparams : CParams(codec=<Codec.ZSTD: 5>, codec_meta=0, clevel=1, use_dict=False, typesize=1,
540540
: nthreads=8, blocksize=0, splitmode=<SplitMode.AUTO_SPLIT: 3>,
541541
: filters=[<Filter.NOFILTER: 0>, <Filter.NOFILTER: 0>, <Filter.NOFILTER: 0>,
@@ -557,7 +557,7 @@ def info_items(self) -> list:
557557
items += [("typesize", self.typesize)]
558558
items += [("nbytes", format_nbytes_info(self.nbytes))]
559559
items += [("cbytes", format_nbytes_info(self.cbytes))]
560-
items += [("cratio", f"{self.cratio:.2f}")]
560+
items += [("cratio", f"{self.cratio:.2f}x")]
561561
items += [("cparams", self.cparams)]
562562
items += [("dparams", self.dparams)]
563563
return items

tests/ctable/test_column.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# SPDX-License-Identifier: BSD-3-Clause
66
#######################################################################
77

8+
import re
89
from dataclasses import dataclass
910

1011
import numpy as np
@@ -91,7 +92,7 @@ def test_column_info():
9192
assert "physical_length" not in text
9293
assert "logical_shape" not in text
9394
assert "table_physical_length" not in text
94-
assert "storage" in text
95+
assert "backend" in text
9596

9697

9798
def test_dictionary_column_info():
@@ -814,7 +815,7 @@ def test_info_shows_open_mode_for_persistent_table(tmp_path):
814815
info = repr(opened.info)
815816
assert "capacity" not in info
816817
assert "read_only" not in info
817-
assert "open_mode : r" in info
818+
assert "open_mode : r" in info
818819
opened.close()
819820

820821

@@ -824,13 +825,6 @@ def test_info_schema_expands_unicode_dtype_labels():
824825
assert "U16 (Unicode)" in info
825826

826827

827-
def test_info_valid_rows_mask_only_reports_cbytes():
828-
t = CTable(Row, new_data=DATA20)
829-
info = repr(t.info)
830-
assert "valid_rows_mask : cbytes=" in info
831-
assert "valid_rows_mask : nbytes=" not in info
832-
833-
834828
def test_info_indexes_only_report_cbytes(tmp_path):
835829
@dataclass
836830
class IndexedRow:
@@ -843,17 +837,18 @@ class IndexedRow:
843837
t.create_index("id", kind=blosc2.IndexKind.FULL)
844838

845839
info = repr(t.info)
846-
index_block = info.split("indexes :", 1)[1]
840+
index_block = info.split("indexes :", 1)[1]
847841
assert "cbytes=" in index_block
848842
assert "nbytes=" not in index_block
849843
assert "cratio=" not in index_block
850844

851845

852-
def test_info_cratio_uses_one_decimal_with_suffix():
846+
def test_info_cratio_uses_two_decimals_with_suffix():
853847
t = CTable(Row, new_data=DATA20)
854848
info = repr(t.info)
855-
assert "cratio :" in info
856-
assert "x" in next(line for line in info.splitlines() if line.startswith("cratio"))
849+
assert "cratio :" in info
850+
cratio_line = next(line for line in info.splitlines() if line.startswith("cratio"))
851+
assert re.search(r"cratio\s+:\s+\d+\.\d{2}x", cratio_line)
857852

858853

859854
# -------------------------------------------------------------------

tests/test_b2view_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_store_browser_metadata_and_previews(tmp_path):
6565

6666
table_info = browser.get_info("/table")
6767
assert table_info.kind == "ctable"
68-
assert table_info.metadata["rows"] == 6
68+
assert table_info.metadata["nrows"] == 6
6969
preview = browser.preview("/table", max_rows=3, max_cols=1)
7070
assert preview["columns"] == ["x"]
7171
assert preview["hidden_columns"] == 1
@@ -83,7 +83,7 @@ def test_store_browser_supports_standalone_ctable(tmp_path):
8383
assert browser.list_children("/") == []
8484
info = browser.get_info("/")
8585
assert info.kind == "ctable"
86-
assert info.metadata["rows"] == 4
86+
assert info.metadata["nrows"] == 4
8787
preview = browser.preview("/", max_rows=2)
8888
np.testing.assert_array_equal(preview["data"]["x"], np.array([0, 1]))
8989

0 commit comments

Comments
 (0)