File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from pathlib import Path
44from typing import TYPE_CHECKING
55
6- import pandas as pd
6+ import polars as pl
77
88from eir .setup import schemas
99from eir .setup .schema_modules .output_schemas_array import (
@@ -194,7 +194,7 @@ def validate_tabular_source(
194194 expected_columns : Sequence [str ],
195195 name : str ,
196196) -> None :
197- header = pd .read_csv (source_to_check , nrows = 0 ).columns . tolist ()
197+ header = pl .read_csv (source_to_check , n_rows = 0 ).columns
198198 if "ID" not in header :
199199 raise ValueError (
200200 f"{ name } file { source_to_check } does not contain a column named 'ID'. "
@@ -208,14 +208,9 @@ def validate_tabular_source(
208208 f"Please check the input file."
209209 )
210210
211- series_ids = pd .read_csv (
212- filepath_or_buffer = source_to_check ,
213- usecols = ["ID" ],
214- engine = "pyarrow" ,
215- dtype_backend = "pyarrow" ,
216- ).squeeze ()
217- if not series_ids .is_unique :
218- non_unique = series_ids [series_ids .duplicated ()].tolist ()
211+ df_ids = pl .read_csv (source_to_check , columns = ["ID" ])
212+ if df_ids ["ID" ].n_unique () != df_ids .height :
213+ non_unique = df_ids .filter (pl .col ("ID" ).is_duplicated ())["ID" ].to_list ()
219214 raise ValueError (
220215 f"{ name } file { source_to_check } contains non-unique"
221216 f" IDs: { reprlib .repr (non_unique )} . "
You can’t perform that action at this time.
0 commit comments