calamari.catalog.build_catalog#
- calamari.catalog.build_catalog(root, *, group_fn=None, dedup_between=None, path_filter=None)#
Build a
Catalog– the inventory of every recognised measurement file underroot, plus the root it resolves against.- Parameters:
group_fn (
Callable[[Path],str] |None) – Maps a file’s path (relative toroot) to a group label string – seesummarise(). Unlike a directsummarise()call,build_catalogalways applies somegroup_fn: if none is given,_default_group_fn()(the first relative path component) is used, so the returned DataFrame always has a'group'column to sort and (optionally) deduplicate by.dedup_between (
tuple[str,str] |None) –(redundant_group, canonical_group)group labels (as produced bygroup_fn) to cross-check same-named summary files for byte equality (including headers and formatting) – see_detect_duplicates(). Default None: no duplicate detection is attempted, and every row getsis_duplicate=False,dup_status=''(the columns are still present, for a consistent schema regardless of whether dedup was requested).path_filter (
Callable[[Path],bool] |None) – Predicate over root-relative file paths, passed tofind_files()before content probing. Excluded files are never opened by calamari, including during duplicate detection. Included files still undergo normal content recognition and metadata classification. For an explicit selection, use e.g.lambda path: path in selectedwith a set of root-relative Paths. Default None: include every candidate. Predicate exceptions propagate; they are not file parse errors.
- Return type:
- Returns:
calamari.catalog.Catalog– One row per recognised file (seesummarise()for columns, plusis_duplicate,canonical_path, anddup_status– see_detect_duplicates()), sorted bygroupthenfilenamethenrelative_path, wrapped withrootas aCatalog(the plain frame is its.df). Files that fail to parse are skipped and reported on.parse_errors(a list of(path, error_message)tuples); filenames genuinely colliding between the twodedup_betweengroups (same name, different content) are listed on.name_collision_differs; the total number of included, recognised files (before parse failures) is.n_scanned. The same three values are mirrored on.df.attrsunder those names.- Raises:
OSError – If
rootis missing (FileNotFoundError), is not a directory (NotADirectoryError), or cannot be listed (PermissionError) – propagated fromfind_files(), so a mistyped root is never reported as an empty catalog.