Closed lasuk closed 3 months ago
Here's a review by ChatGPT:
enforce_dtypes.py
ReviewInputs:
data
: a pandas DataFrame or None
required
: dictionary mapping column names to their required data typesoptional
: dictionary mapping column names to optional data typeskeep_extra_columns
: boolean to keep or drop extra columnsOutputs:
ValueError
if required columns are missing.TypeError
if data type conversion fails.astype()
for other data types.test_enforce_dtypes.py
Reviewkeep_extra_columns
flag.Implements first step in macxred/cashctrl_ledger#2.
Enforce DataFrame Schema
Scope
enforce_dtypes()
that returns a DataFrame with a guaranteed set of columns with known type.list_files()
andlist_categories()
to return a type consistent DataFrame.Background
Converting the results of a GET request from '../list.json' to
pd.DataFrame
returns a reliable DataFrame only when the list is non-empty. If the list is empty, it results in a DataFrame with no columns, which can cause downstream errors.Refer to the Type Consistency section in the CONTRIBUTING.md for more details.