diff --git a/dlccore/io/labeled_data/__init__.py b/dlccore/io/labeled_data/__init__.py index b4b3831..95c7ed0 100644 --- a/dlccore/io/labeled_data/__init__.py +++ b/dlccore/io/labeled_data/__init__.py @@ -9,7 +9,15 @@ # Licensed under GNU Lesser General Public License v3.0 # -"""Labeled-data files: ``model`` holds what is true in any format, and each table format is a subpackage. +"""Labeled-data files. The public API is ``__all__``. + +``__all__`` holds: +- File, model and views +- Arrays view +- Identity types +- Reader and writer +``model`` holds concepts common to all formats. +``_wide``, DeepLabCut's stored table, and ``_checks`` are internal to dlccore; validation reports condition as findings. Imports no format eagerly, so no format's dependencies load until a file is read or written, or that format is imported. diff --git a/dlccore/io/labeled_data/checks/__init__.py b/dlccore/io/labeled_data/_checks/__init__.py similarity index 100% rename from dlccore/io/labeled_data/checks/__init__.py rename to dlccore/io/labeled_data/_checks/__init__.py diff --git a/dlccore/io/labeled_data/checks/file.py b/dlccore/io/labeled_data/_checks/file.py similarity index 93% rename from dlccore/io/labeled_data/checks/file.py rename to dlccore/io/labeled_data/_checks/file.py index 5807d58..c92935f 100644 --- a/dlccore/io/labeled_data/checks/file.py +++ b/dlccore/io/labeled_data/_checks/file.py @@ -21,18 +21,18 @@ import pandas as pd -from dlccore.io.labeled_data.long.model import FRAME_COLUMNS -from dlccore.io.labeled_data.model import LIKELIHOOD_COORD, POSITION_COORDS -from dlccore.io.labeled_data.wide.header import KeypointColumns, LabeledDataHeader, LabeledDataHeaderShape -from dlccore.io.labeled_data.wide.row_index import ( +from dlccore.io.labeled_data._wide.header import KeypointColumns, LabeledDataHeader, LabeledDataHeaderShape +from dlccore.io.labeled_data._wide.row_index import ( LabeledDataRowIndex, RowIndexShape, frame_part_as_text, split_frame_path, ) +from dlccore.io.labeled_data.long.model import FRAME_COLUMNS +from dlccore.io.labeled_data.model import LIKELIHOOD_COORD, POSITION_COORDS if TYPE_CHECKING: - from dlccore.io.labeled_data.wide.h5 import H5KeySelection + from dlccore.io.labeled_data._wide.h5 import H5KeySelection _COORDINATES = frozenset({*POSITION_COORDS, LIKELIHOOD_COORD}) @@ -47,7 +47,7 @@ def unread_h5_keys(selection: H5KeySelection | None) -> tuple[str, ...]: The unread keys, in the file's order. Empty unless the file holds several keys. """ - from dlccore.io.labeled_data.wide.h5 import H5KeySelectionOutcome + from dlccore.io.labeled_data._wide.h5 import H5KeySelectionOutcome if selection is None or selection.outcome is not H5KeySelectionOutcome.MULTI_KEY: return () @@ -64,7 +64,7 @@ def legacy_h5_key(selection: H5KeySelection | None) -> str | None: The key, or ``None`` if the file is not H5, holds another key, or holds several keys. """ - from dlccore.io.labeled_data.wide.h5 import H5KeySelectionOutcome + from dlccore.io.labeled_data._wide.h5 import H5KeySelectionOutcome return _single_key(selection, H5KeySelectionOutcome.SINGLE_LEGACY) @@ -79,7 +79,7 @@ def unknown_h5_key(selection: H5KeySelection | None) -> str | None: The key, or ``None`` if the file is not H5, holds a known key, or holds several keys. """ - from dlccore.io.labeled_data.wide.h5 import H5KeySelectionOutcome + from dlccore.io.labeled_data._wide.h5 import H5KeySelectionOutcome return _single_key(selection, H5KeySelectionOutcome.SINGLE_UNKNOWN) diff --git a/dlccore/io/labeled_data/checks/model.py b/dlccore/io/labeled_data/_checks/model.py similarity index 100% rename from dlccore/io/labeled_data/checks/model.py rename to dlccore/io/labeled_data/_checks/model.py diff --git a/dlccore/io/labeled_data/wide/__init__.py b/dlccore/io/labeled_data/_wide/__init__.py similarity index 100% rename from dlccore/io/labeled_data/wide/__init__.py rename to dlccore/io/labeled_data/_wide/__init__.py diff --git a/dlccore/io/labeled_data/wide/csv.py b/dlccore/io/labeled_data/_wide/csv.py similarity index 93% rename from dlccore/io/labeled_data/wide/csv.py rename to dlccore/io/labeled_data/_wide/csv.py index be7b769..376cff0 100644 --- a/dlccore/io/labeled_data/wide/csv.py +++ b/dlccore/io/labeled_data/_wide/csv.py @@ -24,8 +24,8 @@ import pandas as pd from dlccore.io.errors import UnreadableFileError -from dlccore.io.labeled_data.wide.header import HEADER_DEPTHS, LabeledDataHeaderShape, header_shape -from dlccore.io.labeled_data.wide.table import LabeledDataRead +from dlccore.io.labeled_data._wide.header import HEADER_DEPTHS, LabeledDataHeaderShape, header_shape +from dlccore.io.labeled_data._wide.table import LabeledDataRead def _header_rows_and_index_columns(rows: list[list[str]]) -> tuple[int, int]: @@ -96,7 +96,7 @@ def write_labeled_data_csv(df: pd.DataFrame, path: Path) -> None: """Write a wide table as DeepLabCut's human-readable CSV; the H5 stays authoritative. Values are written as pandas formats them, so a float can differ in its last digits after a round trip, and - the frames ``checks.file.frames_lost_to_csv`` returns are written but read back as something else. + the frames ``_checks.file.frames_lost_to_csv`` returns are written but read back as something else. """ df.to_csv(path) diff --git a/dlccore/io/labeled_data/wide/from_long.py b/dlccore/io/labeled_data/_wide/from_long.py similarity index 95% rename from dlccore/io/labeled_data/wide/from_long.py rename to dlccore/io/labeled_data/_wide/from_long.py index 18e799f..58d80d0 100644 --- a/dlccore/io/labeled_data/wide/from_long.py +++ b/dlccore/io/labeled_data/_wide/from_long.py @@ -15,9 +15,9 @@ import pandas as pd +from dlccore.io.labeled_data._wide.header import MULTI_ANIMAL_LEVELS, SINGLE_ANIMAL_LEVELS from dlccore.io.labeled_data.long.model import FRAME_COLUMNS, LabeledData, identity_columns from dlccore.io.labeled_data.model import LIKELIHOOD_COORD, POSITION_COORDS -from dlccore.io.labeled_data.wide.header import MULTI_ANIMAL_LEVELS, SINGLE_ANIMAL_LEVELS def long_to_wide(labels: LabeledData) -> pd.DataFrame: diff --git a/dlccore/io/labeled_data/wide/h5.py b/dlccore/io/labeled_data/_wide/h5.py similarity index 99% rename from dlccore/io/labeled_data/wide/h5.py rename to dlccore/io/labeled_data/_wide/h5.py index 946d530..d677c0e 100644 --- a/dlccore/io/labeled_data/wide/h5.py +++ b/dlccore/io/labeled_data/_wide/h5.py @@ -24,7 +24,7 @@ import pandas as pd from dlccore.io.errors import UnreadableFileError -from dlccore.io.labeled_data.wide.table import LabeledDataRead +from dlccore.io.labeled_data._wide.table import LabeledDataRead from dlccore.io.stamp import WRITER_KEY, WRITER_VERSION_KEY, WriterStamp # Observed from a payload pandas cannot rebuild: TypeError (unknown storer), NoSuchNodeError diff --git a/dlccore/io/labeled_data/wide/header.py b/dlccore/io/labeled_data/_wide/header.py similarity index 100% rename from dlccore/io/labeled_data/wide/header.py rename to dlccore/io/labeled_data/_wide/header.py diff --git a/dlccore/io/labeled_data/wide/row_index.py b/dlccore/io/labeled_data/_wide/row_index.py similarity index 100% rename from dlccore/io/labeled_data/wide/row_index.py rename to dlccore/io/labeled_data/_wide/row_index.py diff --git a/dlccore/io/labeled_data/wide/storage.py b/dlccore/io/labeled_data/_wide/storage.py similarity index 92% rename from dlccore/io/labeled_data/wide/storage.py rename to dlccore/io/labeled_data/_wide/storage.py index bb5cbed..0ee1386 100644 --- a/dlccore/io/labeled_data/wide/storage.py +++ b/dlccore/io/labeled_data/_wide/storage.py @@ -26,10 +26,10 @@ from dlccore.io.errors import FileChangedError from dlccore.io.file_stat import FileStat +from dlccore.io.labeled_data._wide.header import LabeledDataHeader, LabeledDataHeaderShape +from dlccore.io.labeled_data._wide.row_index import LabeledDataRowIndex, RowIndexShape, frame_part_as_text +from dlccore.io.labeled_data._wide.table import LabeledDataRead, classify_labeled_data_read from dlccore.io.labeled_data.model import FramePath, Keypoint -from dlccore.io.labeled_data.wide.header import LabeledDataHeader, LabeledDataHeaderShape -from dlccore.io.labeled_data.wide.row_index import LabeledDataRowIndex, RowIndexShape, frame_part_as_text -from dlccore.io.labeled_data.wide.table import LabeledDataRead, classify_labeled_data_read from dlccore.io.stamp import WriterStamp from dlccore.io.suffixes import ( CSV_SUFFIX, @@ -39,8 +39,8 @@ ) if TYPE_CHECKING: + from dlccore.io.labeled_data._wide.h5 import H5KeySelection from dlccore.io.labeled_data.long.model import LabeledData - from dlccore.io.labeled_data.wide.h5 import H5KeySelection @dataclass(frozen=True, eq=False) @@ -97,13 +97,13 @@ def wide_suffix(path: Path) -> str | None: def _read_h5(path: Path) -> LabeledDataRead: - from dlccore.io.labeled_data.wide.h5 import read_labeled_data_h5 + from dlccore.io.labeled_data._wide.h5 import read_labeled_data_h5 return read_labeled_data_h5(path) def _read_csv(path: Path) -> LabeledDataRead: - from dlccore.io.labeled_data.wide.csv import read_labeled_data_csv + from dlccore.io.labeled_data._wide.csv import read_labeled_data_csv return read_labeled_data_csv(path) @@ -175,10 +175,10 @@ def write_wide_labeled_data(labels: LabeledData, path: Path, *, replaces: FileSt UserWarning: Once both files are in place, for each frame the CSV twin reads back without. """ - from dlccore.io.labeled_data.checks.file import frames_lost_to_csv, unread_h5_keys - from dlccore.io.labeled_data.checks.model import keypoints_with_empty_individual, likelihood_in_human_labels - from dlccore.io.labeled_data.wide.csv import write_labeled_data_csv - from dlccore.io.labeled_data.wide.h5 import select_h5_key, write_labeled_data_h5 + from dlccore.io.labeled_data._checks.file import frames_lost_to_csv, unread_h5_keys + from dlccore.io.labeled_data._checks.model import keypoints_with_empty_individual, likelihood_in_human_labels + from dlccore.io.labeled_data._wide.csv import write_labeled_data_csv + from dlccore.io.labeled_data._wide.h5 import select_h5_key, write_labeled_data_h5 if suffix_in(path, frozenset({H5_SUFFIX})) is None: raise ValueError(f"{path}: the labeled-data writer writes an .h5 file and its .csv twin; got {path.suffix!r}.") diff --git a/dlccore/io/labeled_data/wide/table.py b/dlccore/io/labeled_data/_wide/table.py similarity index 89% rename from dlccore/io/labeled_data/wide/table.py rename to dlccore/io/labeled_data/_wide/table.py index 23bc175..4896843 100644 --- a/dlccore/io/labeled_data/wide/table.py +++ b/dlccore/io/labeled_data/_wide/table.py @@ -23,11 +23,11 @@ import pandas as pd -from dlccore.io.labeled_data.wide.header import LabeledDataHeader, classify_labeled_data_header -from dlccore.io.labeled_data.wide.row_index import LabeledDataRowIndex, classify_labeled_data_row_index +from dlccore.io.labeled_data._wide.header import LabeledDataHeader, classify_labeled_data_header +from dlccore.io.labeled_data._wide.row_index import LabeledDataRowIndex, classify_labeled_data_row_index if TYPE_CHECKING: - from dlccore.io.labeled_data.wide.h5 import H5KeySelection + from dlccore.io.labeled_data._wide.h5 import H5KeySelection from dlccore.io.stamp import WriterStamp diff --git a/dlccore/io/labeled_data/wide/to_long.py b/dlccore/io/labeled_data/_wide/to_long.py similarity index 95% rename from dlccore/io/labeled_data/wide/to_long.py rename to dlccore/io/labeled_data/_wide/to_long.py index 6644d79..c8f5581 100644 --- a/dlccore/io/labeled_data/wide/to_long.py +++ b/dlccore/io/labeled_data/_wide/to_long.py @@ -22,7 +22,7 @@ import numpy as np import pandas as pd -from dlccore.io.labeled_data.checks.file import ( +from dlccore.io.labeled_data._checks.file import ( frames_of_other_depth, frames_with_unnamed_parts, has_no_frames, @@ -32,15 +32,15 @@ non_numeric_columns, row_index_is_unrecognised, ) +from dlccore.io.labeled_data._wide.header import LabeledDataHeader, LabeledDataHeaderShape +from dlccore.io.labeled_data._wide.row_index import LabeledDataRowIndex, frame_part_as_text +from dlccore.io.labeled_data._wide.table import classify_wide_df from dlccore.io.labeled_data.long.model import ( FRAME_COLUMNS, LabeledData, identity_values, ) from dlccore.io.labeled_data.model import LIKELIHOOD_COORD, POSITION_COORDS -from dlccore.io.labeled_data.wide.header import LabeledDataHeader, LabeledDataHeaderShape -from dlccore.io.labeled_data.wide.row_index import LabeledDataRowIndex, frame_part_as_text -from dlccore.io.labeled_data.wide.table import classify_wide_df def wide_to_long( diff --git a/dlccore/io/labeled_data/file.py b/dlccore/io/labeled_data/file.py index 86b2e0f..728dfa1 100644 --- a/dlccore/io/labeled_data/file.py +++ b/dlccore/io/labeled_data/file.py @@ -23,11 +23,11 @@ if TYPE_CHECKING: import pandas as pd + from dlccore.io.labeled_data._wide.h5 import H5KeySelection + from dlccore.io.labeled_data._wide.header import LabeledDataHeader + from dlccore.io.labeled_data._wide.row_index import LabeledDataRowIndex + from dlccore.io.labeled_data._wide.storage import WideLabeledDataStorage from dlccore.io.labeled_data.long.model import LabeledData - from dlccore.io.labeled_data.wide.h5 import H5KeySelection - from dlccore.io.labeled_data.wide.header import LabeledDataHeader - from dlccore.io.labeled_data.wide.row_index import LabeledDataRowIndex - from dlccore.io.labeled_data.wide.storage import WideLabeledDataStorage from dlccore.io.stamp import WriterStamp @@ -98,7 +98,7 @@ def labeled_data(self) -> LabeledData: ValueError: Naming the file and why it has no model, e.g. a frame of other than three parts. """ - from dlccore.io.labeled_data.wide.to_long import wide_to_long + from dlccore.io.labeled_data._wide.to_long import wide_to_long try: return wide_to_long(self._stored.dataframe, self._stored.header, self._stored.row_index) @@ -126,7 +126,7 @@ def read_labeled_data(path: Path) -> LabeledDataFile: ValueError: If no reader handles the suffix. """ - from dlccore.io.labeled_data.wide.storage import read_wide_labeled_data + from dlccore.io.labeled_data._wide.storage import read_wide_labeled_data try: stat = FileStat.of(path) @@ -166,6 +166,6 @@ def write_labeled_data(labels: LabeledData, path: Path, *, replaces: FileStat | without values, which pandas and DeepLabCut read as the row index's names. The H5 keeps it. """ - from dlccore.io.labeled_data.wide.storage import write_wide_labeled_data + from dlccore.io.labeled_data._wide.storage import write_wide_labeled_data return write_wide_labeled_data(labels, path, replaces=replaces) diff --git a/dlccore/io/labeled_data/long/model.py b/dlccore/io/labeled_data/long/model.py index 77c7ad4..78ef36a 100644 --- a/dlccore/io/labeled_data/long/model.py +++ b/dlccore/io/labeled_data/long/model.py @@ -82,7 +82,7 @@ def from_wide_df(cls, df: pd.DataFrame) -> LabeledData: ValueError: If ``df`` cannot be converted; see ``wide.to_long.wide_to_long`` for the cases. """ - from dlccore.io.labeled_data.wide.to_long import wide_df_to_long + from dlccore.io.labeled_data._wide.to_long import wide_df_to_long return wide_df_to_long(df) @@ -100,7 +100,7 @@ def to_arrays(self) -> LabeledDataArrays: return long_to_arrays(self) def to_wide_df(self) -> pd.DataFrame: - from dlccore.io.labeled_data.wide.from_long import long_to_wide + from dlccore.io.labeled_data._wide.from_long import long_to_wide return long_to_wide(self) diff --git a/tests/io/fixtures/labeled_data/README.md b/tests/io/fixtures/labeled_data/README.md index 60199b6..30071f9 100644 --- a/tests/io/fixtures/labeled_data/README.md +++ b/tests/io/fixtures/labeled_data/README.md @@ -28,7 +28,7 @@ Written with a local napari-deeplabcut checkout at the producer commit below. - `deeplabcut.utils.auxfun_multianimal.convert_single2multiplelegacyAM(config, userfeedback=False, target="multi")`, from a hand-built 3-level single-animal file whose multi-animal bodyparts are named `_`. Nothing in DeepLabCut calls this function; the header shape it writes is the one labeling writes; - `deeplabcut.generate_training_dataset.trainingsetmanipulation.dropduplicatesinannotatinfiles(config)`, from a hand-built single-animal file with a flat string row index and one row twice. - **Only these paths**: DeepLabCut's labeling and `convert2_maDLC` write the same header shapes by other code; neither is exercised here. -- **Bytes are not reproducible**: HDF5 stamps every object with its write time, so a rerun writes a different `.h5` holding an equal table. The 2026-10-10 and 2026-10-12 runs differ in 72 bytes across 24 objects, all timestamps. Each `.csv` reads back equal to its `.h5` twin (`tests/io/labeled_data/wide/test_csv.py`). +- **Bytes are not reproducible**: HDF5 stamps every object with its write time, so a rerun writes a different `.h5` holding an equal table. The 2026-10-10 and 2026-10-12 runs differ in 72 bytes across 24 objects, all timestamps. Each `.csv` reads back equal to its `.h5` twin (`tests/io/labeled_data/_wide/test_csv.py`). | File | Animals | Source | Row index | Notes | |---|---|---|---|---| @@ -43,4 +43,4 @@ Rerun 2026-10-16 with deeplabcut 3.0.2, pandas 2.3.3, PyTables 3.11.1 and numpy **Both projects read keyless**; `pd.read_hdf(path)` with no key succeeds for any single-key file. So a project labeled with both tools in that period legitimately holds both keys, one per video folder. -A `keypoints` file is therefore real labeled data produced by the GUI DeepLabCut ships for labelling, not a corrupt or exotic file. Fixtures covering it exist so that stays true. The registry entry asserting it is `LEGACY` is pinned by `tests/io/labeled_data/wide/test_h5.py`. +A `keypoints` file is therefore real labeled data produced by the GUI DeepLabCut ships for labelling, not a corrupt or exotic file. Fixtures covering it exist so that stays true. The registry entry asserting it is `LEGACY` is pinned by `tests/io/labeled_data/_wide/test_h5.py`. diff --git a/tests/io/labeled_data/test_checks.py b/tests/io/labeled_data/test_checks.py index ce3b5d8..11f84d3 100644 --- a/tests/io/labeled_data/test_checks.py +++ b/tests/io/labeled_data/test_checks.py @@ -16,7 +16,7 @@ import pytest from dlccore.io.labeled_data import Keypoint, LabeledData, read_labeled_data -from dlccore.io.labeled_data.checks.file import ( +from dlccore.io.labeled_data._checks.file import ( frame_absorbed_into_index_names, frames_of_other_depth, frames_with_unnamed_parts, @@ -28,14 +28,14 @@ row_index_is_unrecognised, unread_h5_keys, ) -from dlccore.io.labeled_data.checks.model import ( +from dlccore.io.labeled_data._checks.model import ( keypoints_with_empty_individual, likelihood_in_human_labels, missing_keypoints, ) -from dlccore.io.labeled_data.wide.h5 import H5KeySelectionOutcome, select_h5_key -from dlccore.io.labeled_data.wide.header import LabeledDataHeader, classify_labeled_data_header -from dlccore.io.labeled_data.wide.row_index import LabeledDataRowIndex, classify_labeled_data_row_index +from dlccore.io.labeled_data._wide.h5 import H5KeySelectionOutcome, select_h5_key +from dlccore.io.labeled_data._wide.header import LabeledDataHeader, classify_labeled_data_header +from dlccore.io.labeled_data._wide.row_index import LabeledDataRowIndex, classify_labeled_data_row_index FIXTURES_DIR = Path(__file__).parents[1] / "fixtures" / "labeled_data" SINGLE_ANIMAL_LEVELS = ["scorer", "bodyparts", "coords"] @@ -253,8 +253,8 @@ def test_index_names_that_spell_no_three_part_frame_are_not_found(names: tuple[o def test_checks_are_split_into_file_and_model_facts() -> None: - importlib.import_module("dlccore.io.labeled_data.checks.file") - importlib.import_module("dlccore.io.labeled_data.checks.model") + importlib.import_module("dlccore.io.labeled_data._checks.file") + importlib.import_module("dlccore.io.labeled_data._checks.model") def test_a_keypoint_whose_individual_is_named_empty_is_found() -> None: diff --git a/tests/io/labeled_data/test_file.py b/tests/io/labeled_data/test_file.py index 313be18..27627d1 100644 --- a/tests/io/labeled_data/test_file.py +++ b/tests/io/labeled_data/test_file.py @@ -17,7 +17,7 @@ import dlccore.io.labeled_data as labeled_data from dlccore.io.errors import UnreadableFileError from dlccore.io.labeled_data import LabeledData, LabeledDataFile, read_labeled_data, write_labeled_data -from dlccore.io.labeled_data.wide.storage import WideLabeledDataStorage, read_wide_labeled_data +from dlccore.io.labeled_data._wide.storage import WideLabeledDataStorage, read_wide_labeled_data FIXTURES_DIR = Path(__file__).parents[1] / "fixtures" / "labeled_data" FIXTURES = sorted(path.name for path in FIXTURES_DIR.glob("*") if path.suffix in {".h5", ".csv"}) diff --git a/tests/io/labeled_data/test_write.py b/tests/io/labeled_data/test_write.py index 6c4a721..565eda7 100644 --- a/tests/io/labeled_data/test_write.py +++ b/tests/io/labeled_data/test_write.py @@ -24,8 +24,8 @@ from dlccore.io import FileChangedError, FileStat from dlccore.io.labeled_data import LabeledData, read_labeled_data, write_labeled_data -from dlccore.io.labeled_data.checks.file import frames_lost_to_csv -from dlccore.io.labeled_data.wide.storage import csv_twin +from dlccore.io.labeled_data._checks.file import frames_lost_to_csv +from dlccore.io.labeled_data._wide.storage import csv_twin from dlccore.io.stamp import WRITER_KEY, WRITER_VERSION_KEY, WriterStamp FIXTURES_DIR = Path(__file__).parents[1] / "fixtures" / "labeled_data" @@ -374,7 +374,7 @@ def test_files_beside_the_target_survive_a_write(tmp_path: Path) -> None: def test_reading_records_the_stat_taken_before_the_read(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: - from dlccore.io.labeled_data.wide import storage + from dlccore.io.labeled_data._wide import storage path = tmp_path / "CollectedData_Sc.h5" path.write_bytes((FIXTURES_DIR / "single_animal_human.h5").read_bytes()) diff --git a/tests/io/labeled_data/wide/test_csv.py b/tests/io/labeled_data/wide/test_csv.py index b714fe8..b0dbfdd 100644 --- a/tests/io/labeled_data/wide/test_csv.py +++ b/tests/io/labeled_data/wide/test_csv.py @@ -16,10 +16,10 @@ import pytest from dlccore.io.errors import UnreadableFileError -from dlccore.io.labeled_data.wide.csv import read_labeled_data_csv -from dlccore.io.labeled_data.wide.h5 import read_labeled_data_h5 -from dlccore.io.labeled_data.wide.header import LabeledDataHeaderShape -from dlccore.io.labeled_data.wide.table import classify_labeled_data_read +from dlccore.io.labeled_data._wide.csv import read_labeled_data_csv +from dlccore.io.labeled_data._wide.h5 import read_labeled_data_h5 +from dlccore.io.labeled_data._wide.header import LabeledDataHeaderShape +from dlccore.io.labeled_data._wide.table import classify_labeled_data_read FIXTURES_DIR = Path(__file__).parents[2] / "fixtures" / "labeled_data" CSV_FIXTURES = sorted(path.name for path in FIXTURES_DIR.glob("*.csv")) diff --git a/tests/io/labeled_data/wide/test_from_long.py b/tests/io/labeled_data/wide/test_from_long.py index 6618dc6..1cc4c3c 100644 --- a/tests/io/labeled_data/wide/test_from_long.py +++ b/tests/io/labeled_data/wide/test_from_long.py @@ -15,10 +15,10 @@ import pandas as pd import pytest +from dlccore.io.labeled_data._wide.from_long import long_to_wide +from dlccore.io.labeled_data._wide.storage import read_wide_labeled_data +from dlccore.io.labeled_data._wide.to_long import wide_df_to_long, wide_to_long from dlccore.io.labeled_data.long.model import LabeledData -from dlccore.io.labeled_data.wide.from_long import long_to_wide -from dlccore.io.labeled_data.wide.storage import read_wide_labeled_data -from dlccore.io.labeled_data.wide.to_long import wide_df_to_long, wide_to_long FIXTURES_DIR = Path(__file__).parents[2] / "fixtures" / "labeled_data" FIXTURES = sorted(path.name for path in FIXTURES_DIR.glob("*") if path.suffix in {".h5", ".csv"}) diff --git a/tests/io/labeled_data/wide/test_h5.py b/tests/io/labeled_data/wide/test_h5.py index 38941e9..be3c0ab 100644 --- a/tests/io/labeled_data/wide/test_h5.py +++ b/tests/io/labeled_data/wide/test_h5.py @@ -16,7 +16,7 @@ import tables from dlccore.io.errors import UnreadableFileError -from dlccore.io.labeled_data.wide.h5 import ( +from dlccore.io.labeled_data._wide.h5 import ( H5_KEY_REGISTRY, H5KeySelection, H5KeySelectionOutcome, diff --git a/tests/io/labeled_data/wide/test_header.py b/tests/io/labeled_data/wide/test_header.py index a758783..49eceef 100644 --- a/tests/io/labeled_data/wide/test_header.py +++ b/tests/io/labeled_data/wide/test_header.py @@ -14,14 +14,14 @@ import pytest -from dlccore.io.labeled_data.model import BodypartScope -from dlccore.io.labeled_data.wide.h5 import read_labeled_data_h5 -from dlccore.io.labeled_data.wide.header import ( +from dlccore.io.labeled_data._wide.h5 import read_labeled_data_h5 +from dlccore.io.labeled_data._wide.header import ( LabeledDataHeader, LabeledDataHeaderShape, classify_labeled_data_header, ) -from dlccore.io.labeled_data.wide.table import classify_labeled_data_read +from dlccore.io.labeled_data._wide.table import classify_labeled_data_read +from dlccore.io.labeled_data.model import BodypartScope FIXTURES_DIR = Path(__file__).parents[2] / "fixtures" / "labeled_data" FIXTURES = sorted(path.name for path in FIXTURES_DIR.glob("*.h5")) diff --git a/tests/io/labeled_data/wide/test_row_index.py b/tests/io/labeled_data/wide/test_row_index.py index b2ca445..f5a9932 100644 --- a/tests/io/labeled_data/wide/test_row_index.py +++ b/tests/io/labeled_data/wide/test_row_index.py @@ -15,14 +15,14 @@ import pandas as pd import pytest -from dlccore.io.labeled_data.wide.h5 import read_labeled_data_h5 -from dlccore.io.labeled_data.wide.row_index import ( +from dlccore.io.labeled_data._wide.h5 import read_labeled_data_h5 +from dlccore.io.labeled_data._wide.row_index import ( RowIndexShape, classify_labeled_data_row_index, frame_part_as_text, split_frame_path, ) -from dlccore.io.labeled_data.wide.table import classify_labeled_data_read +from dlccore.io.labeled_data._wide.table import classify_labeled_data_read FIXTURES_DIR = Path(__file__).parents[2] / "fixtures" / "labeled_data" FIXTURES = sorted(path.name for path in FIXTURES_DIR.glob("*.h5")) diff --git a/tests/io/labeled_data/wide/test_storage.py b/tests/io/labeled_data/wide/test_storage.py index cebf9ed..9b8433c 100644 --- a/tests/io/labeled_data/wide/test_storage.py +++ b/tests/io/labeled_data/wide/test_storage.py @@ -17,11 +17,11 @@ from dlccore.io.errors import UnreadableFileError from dlccore.io.labeled_data import LabeledData -from dlccore.io.labeled_data.wide.csv import read_labeled_data_csv -from dlccore.io.labeled_data.wide.h5 import read_labeled_data_h5 -from dlccore.io.labeled_data.wide.storage import WideLabeledDataStorage, read_wide_labeled_data -from dlccore.io.labeled_data.wide.table import LabeledDataRead, classify_labeled_data_read -from dlccore.io.labeled_data.wide.to_long import wide_to_long +from dlccore.io.labeled_data._wide.csv import read_labeled_data_csv +from dlccore.io.labeled_data._wide.h5 import read_labeled_data_h5 +from dlccore.io.labeled_data._wide.storage import WideLabeledDataStorage, read_wide_labeled_data +from dlccore.io.labeled_data._wide.table import LabeledDataRead, classify_labeled_data_read +from dlccore.io.labeled_data._wide.to_long import wide_to_long FIXTURES_DIR = Path(__file__).parents[2] / "fixtures" / "labeled_data" FIXTURES = sorted(path.name for path in FIXTURES_DIR.glob("*") if path.suffix in {".h5", ".csv"}) diff --git a/tests/io/labeled_data/wide/test_to_long.py b/tests/io/labeled_data/wide/test_to_long.py index d665cd5..51b9019 100644 --- a/tests/io/labeled_data/wide/test_to_long.py +++ b/tests/io/labeled_data/wide/test_to_long.py @@ -15,9 +15,9 @@ import pandas as pd import pytest +from dlccore.io.labeled_data._wide.storage import read_wide_labeled_data +from dlccore.io.labeled_data._wide.to_long import wide_df_to_long, wide_to_long from dlccore.io.labeled_data.long.model import LabeledData -from dlccore.io.labeled_data.wide.storage import read_wide_labeled_data -from dlccore.io.labeled_data.wide.to_long import wide_df_to_long, wide_to_long FIXTURES_DIR = Path(__file__).parents[2] / "fixtures" / "labeled_data" FIXTURES = sorted(path.name for path in FIXTURES_DIR.glob("*") if path.suffix in {".h5", ".csv"}) diff --git a/tests/io/test_boundaries.py b/tests/io/test_boundaries.py index d3fe42d..c8a4583 100644 --- a/tests/io/test_boundaries.py +++ b/tests/io/test_boundaries.py @@ -71,6 +71,23 @@ def test_io_imports_nothing_from_dlccore_outside_io() -> None: assert {module: names for module, names in offending.items() if names} == {} +PRIVATE_LABELED_DATA = (f"{IO}.labeled_data._wide", f"{IO}.labeled_data._checks") + + +def _private_labeled_data_imports() -> dict[str, list[str]]: + return { + module: sorted(name for name in imports if any(_within(name, private) for private in PRIVATE_LABELED_DATA)) + for module, imports in _package_modules() + } + + +def test_only_io_imports_the_private_labeled_data_modules() -> None: + found = _private_labeled_data_imports() + + assert found[f"{IO}.labeled_data.file"] # control: the file class reads through _wide + assert {module: names for module, names in found.items() if names and not _within(module, IO)} == {} + + def test_the_scan_reaches_io() -> None: # Control: io's own __init__ imports its errors module, so an empty scan cannot pass the test above. assert f"{IO}.errors" in dict(_package_modules())[IO] @@ -99,7 +116,7 @@ def test_a_relative_import_in_a_package_init_resolves_inside_it() -> None: assert f"{IO}.fingerprints" in found -_FRESH_IMPORTS = (IO, f"{IO}.labeled_data.wide", f"{IO}.labeled_data.wide.h5", f"{IO}.labeled_data") +_FRESH_IMPORTS = (IO, f"{IO}.labeled_data._wide", f"{IO}.labeled_data._wide.h5", f"{IO}.labeled_data") _UNLOAD_AND_IMPORT_EACH = f""" import importlib, sys for module in {_FRESH_IMPORTS!r}: @@ -130,17 +147,17 @@ def test_importing_io_loads_its_fingerprints() -> None: def test_each_fresh_import_starts_without_the_previous_ones() -> None: # Control: the h5 module is imported just before its grandparent package, which does not import it. - assert f"{IO}.labeled_data.wide.h5" in _loaded_by_importing()[f"{IO}.labeled_data.wide.h5"] - assert f"{IO}.labeled_data.wide.h5" not in _loaded_by_importing()[f"{IO}.labeled_data"] + assert f"{IO}.labeled_data._wide.h5" in _loaded_by_importing()[f"{IO}.labeled_data._wide.h5"] + assert f"{IO}.labeled_data._wide.h5" not in _loaded_by_importing()[f"{IO}.labeled_data"] def test_importing_io_does_not_load_the_video_module() -> None: assert f"{IO}.video" not in _loaded_by_importing()[IO] -@pytest.mark.parametrize("package", [f"{IO}.labeled_data", f"{IO}.labeled_data.wide"]) +@pytest.mark.parametrize("package", [f"{IO}.labeled_data", f"{IO}.labeled_data._wide"]) def test_importing_a_labeled_data_package_does_not_load_the_h5_module(package: str) -> None: - assert f"{IO}.labeled_data.wide.h5" not in _loaded_by_importing()[package] + assert f"{IO}.labeled_data._wide.h5" not in _loaded_by_importing()[package] _FILE_MODULE = PACKAGE_ROOT / "io" / "labeled_data" / "file.py"