Skip to content

Commit

Permalink
depr(python): Rename dtypes parameter to schema_overrides for `re…
Browse files Browse the repository at this point in the history
…ad_csv`/`scan_csv`/`read_csv_batched` (pola-rs#16628)
  • Loading branch information
stinodego committed May 31, 2024
1 parent 4e95200 commit 5974ac7
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 132 deletions.
4 changes: 2 additions & 2 deletions docs/src/python/user-guide/expressions/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
# --8<-- [start:dataframe]
url = "https://theunitedstates.io/congress-legislators/legislators-historical.csv"

dtypes = {
schema_overrides = {
"first_name": pl.Categorical,
"gender": pl.Categorical,
"type": pl.Categorical,
"state": pl.Categorical,
"party": pl.Categorical,
}

dataset = pl.read_csv(url, dtypes=dtypes).with_columns(
dataset = pl.read_csv(url, schema_overrides=schema_overrides).with_columns(
pl.col("birthday").str.to_date(strict=False)
)
# --8<-- [end:dataframe]
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/_utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _rename_keyword_argument(
)
raise TypeError(msg)
issue_deprecation_warning(
f"`the argument {old_name}` for `{func_name}` is deprecated."
f"The argument `{old_name}` for `{func_name}` is deprecated."
f" It has been renamed to `{new_name}`.",
version=version,
)
Expand Down
14 changes: 7 additions & 7 deletions py-polars/polars/io/csv/batched_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
comment_prefix: str | None = None,
quote_char: str | None = '"',
skip_rows: int = 0,
dtypes: None | (SchemaDict | Sequence[PolarsDataType]) = None,
schema_overrides: SchemaDict | Sequence[PolarsDataType] | None = None,
null_values: str | Sequence[str] | dict[str, str] | None = None,
missing_utf8_is_empty_string: bool = False,
ignore_errors: bool = False,
Expand All @@ -61,15 +61,15 @@ def __init__(

dtype_list: Sequence[tuple[str, PolarsDataType]] | None = None
dtype_slice: Sequence[PolarsDataType] | None = None
if dtypes is not None:
if isinstance(dtypes, dict):
if schema_overrides is not None:
if isinstance(schema_overrides, dict):
dtype_list = []
for k, v in dtypes.items():
for k, v in schema_overrides.items():
dtype_list.append((k, py_type_to_dtype(v)))
elif isinstance(dtypes, Sequence):
dtype_slice = dtypes
elif isinstance(schema_overrides, Sequence):
dtype_slice = schema_overrides
else:
msg = "`dtypes` arg should be list or dict"
msg = "`schema_overrides` arg should be list or dict"
raise TypeError(msg)

processed_null_values = _process_null_values(null_values)
Expand Down
Loading

0 comments on commit 5974ac7

Please sign in to comment.