Skip to content

Commit 69d1339

Browse files
authored
Wrap long strings (#4144)
1 parent b326afd commit 69d1339

14 files changed

+115
-49
lines changed

py-polars/polars/internals/construction.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def sequence_to_pyseries(
188188
if dtype_ in py_temporal_types:
189189
if not _PYARROW_AVAILABLE: # pragma: no cover
190190
raise ImportError(
191-
"'pyarrow' is required for converting a Sequence of date or datetime values to a PySeries."
191+
"'pyarrow' is required for converting a Sequence of date or"
192+
" datetime values to a PySeries."
192193
)
193194
# let arrow infer dtype if not timedelta
194195
# arrow uses microsecond durations by default, not supported yet.
@@ -670,7 +671,8 @@ def pandas_to_pydf(
670671
"""
671672
if not _PYARROW_AVAILABLE: # pragma: no cover
672673
raise ImportError(
673-
"'pyarrow' is required when constructing a PyDataFrame from a pandas DataFrame."
674+
"'pyarrow' is required when constructing a PyDataFrame from a pandas"
675+
" DataFrame."
674676
)
675677
length = data.shape[0]
676678
arrow_dict = {

py-polars/polars/internals/expr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7036,7 +7036,8 @@ def expr_to_lit_or_expr(
70367036
return pli.lit(pli.Series("", [expr]))
70377037
else:
70387038
raise ValueError(
7039-
f"did not expect value {expr} of type {type(expr)}, maybe disambiguate with pl.lit or pl.col"
7039+
f"did not expect value {expr} of type {type(expr)}, maybe disambiguate with"
7040+
" pl.lit or pl.col"
70407041
)
70417042

70427043

py-polars/polars/internals/frame.py

+32-16
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ def __init__(
322322
elif _PANDAS_AVAILABLE and isinstance(data, pd.DataFrame):
323323
if not _PYARROW_AVAILABLE: # pragma: no cover
324324
raise ImportError(
325-
"'pyarrow' is required for converting a pandas DataFrame to a polars DataFrame."
325+
"'pyarrow' is required for converting a pandas DataFrame to a"
326+
" polars DataFrame."
326327
)
327328
self._df = pandas_to_pydf(data, columns=columns)
328329

@@ -580,7 +581,8 @@ def _read_csv(
580581
dtypes_dict = {name: dt for (name, dt) in dtype_list}
581582
if dtype_slice is not None:
582583
raise ValueError(
583-
"cannot use glob patterns and unnamed dtypes as `dtypes` argument; Use dtypes: Mapping[str, Type[DataType]"
584+
"cannot use glob patterns and unnamed dtypes as `dtypes` argument;"
585+
" Use dtypes: Mapping[str, Type[DataType]"
584586
)
585587
from polars import scan_csv
586588

@@ -609,7 +611,8 @@ def _read_csv(
609611
return self._from_pydf(scan.select(columns).collect()._df)
610612
else:
611613
raise ValueError(
612-
"cannot use glob patterns and integer based projection as `columns` argument; Use columns: List[str]"
614+
"cannot use glob patterns and integer based projection as `columns`"
615+
" argument; Use columns: List[str]"
613616
)
614617

615618
projection, columns = handle_projection_columns(columns)
@@ -683,7 +686,8 @@ def _read_parquet(
683686
return cls._from_pydf(scan.select(columns).collect()._df)
684687
else:
685688
raise ValueError(
686-
"cannot use glob patterns and integer based projection as `columns` argument; Use columns: List[str]"
689+
"cannot use glob patterns and integer based projection as `columns`"
690+
" argument; Use columns: List[str]"
687691
)
688692

689693
projection, columns = handle_projection_columns(columns)
@@ -775,7 +779,8 @@ def _read_ipc(
775779
return scan.select(columns).collect()
776780
else:
777781
raise ValueError(
778-
"cannot use glob patterns and integer based projection as `columns` argument; Use columns: List[str]"
782+
"cannot use glob patterns and integer based projection as `columns`"
783+
" argument; Use columns: List[str]"
779784
)
780785

781786
projection, columns = handle_projection_columns(columns)
@@ -819,7 +824,8 @@ def to_arrow(self) -> pa.Table:
819824
"""
820825
if not _PYARROW_AVAILABLE: # pragma: no cover
821826
raise ImportError(
822-
"'pyarrow' is required for converting a polars DataFrame to an Arrow Table."
827+
"'pyarrow' is required for converting a polars DataFrame to an Arrow"
828+
" Table."
823829
)
824830
record_batches = self._df.to_arrow()
825831
return pa.Table.from_batches(record_batches)
@@ -1437,7 +1443,8 @@ def write_parquet(
14371443
if use_pyarrow:
14381444
if not _PYARROW_AVAILABLE: # pragma: no cover
14391445
raise ImportError(
1440-
"'pyarrow' is required when using 'write_parquet(..., use_pyarrow=True)'."
1446+
"'pyarrow' is required when using"
1447+
" 'write_parquet(..., use_pyarrow=True)'."
14411448
)
14421449

14431450
tbl = self.to_arrow()
@@ -1765,7 +1772,8 @@ def __getitem__(
17651772
return self._from_pydf(self._df.select(item))
17661773
if item.dtype == bool:
17671774
warnings.warn(
1768-
"index notation '[]' is deprecated for boolean masks. Consider using 'filter'.",
1775+
"index notation '[]' is deprecated for boolean masks. Consider"
1776+
" using 'filter'.",
17691777
DeprecationWarning,
17701778
)
17711779
return self._from_pydf(self._df.filter(pli.Series("", item).inner()))
@@ -1798,7 +1806,8 @@ def __setitem__(
17981806
self, key: str | list | tuple[Any, str | int], value: Any
17991807
) -> None: # pragma: no cover
18001808
warnings.warn(
1801-
"setting a DataFrame by indexing is deprecated; Consider using DataFrame.with_column",
1809+
"setting a DataFrame by indexing is deprecated; Consider using"
1810+
" DataFrame.with_column",
18021811
DeprecationWarning,
18031812
)
18041813
# df["foo"] = series
@@ -1817,7 +1826,8 @@ def __setitem__(
18171826
raise ValueError("can only set multiple columns with 2D matrix")
18181827
if value.shape[1] != len(key):
18191828
raise ValueError(
1820-
"matrix columns should be equal to list use to determine column names"
1829+
"matrix columns should be equal to list use to determine column"
1830+
" names"
18211831
)
18221832
for (i, name) in enumerate(key):
18231833
self[name] = value[:, i]
@@ -3660,7 +3670,8 @@ def join(
36603670
"""
36613671
if how == "asof": # pragma: no cover
36623672
warnings.warn(
3663-
"using asof join via DataFrame.join is deprecated, please use DataFrame.join_asof",
3673+
"using asof join via DataFrame.join is deprecated, please use"
3674+
" DataFrame.join_asof",
36643675
DeprecationWarning,
36653676
)
36663677
if how == "cross":
@@ -3842,7 +3853,8 @@ def with_column(self: DF, column: pli.Series | pli.Expr) -> DF:
38423853
"""
38433854
if isinstance(column, list):
38443855
raise ValueError(
3845-
"`with_column` expects a single expression, not a list. Consider using `with_columns`"
3856+
"`with_column` expects a single expression, not a list. Consider using"
3857+
" `with_columns`"
38463858
)
38473859
if isinstance(column, pli.Expr):
38483860
return self.with_columns([column])
@@ -6102,7 +6114,8 @@ def _select(self, columns: str | list[str]) -> GBSelection[DF]: # pragma: no co
61026114
One or multiple columns.
61036115
"""
61046116
warnings.warn(
6105-
"accessing GroupBy by index is deprecated, consider using the `.agg` method",
6117+
"accessing GroupBy by index is deprecated, consider using the `.agg`"
6118+
" method",
61066119
DeprecationWarning,
61076120
)
61086121
if isinstance(columns, str):
@@ -6218,7 +6231,8 @@ def groups(self) -> DF: # pragma: no cover
62186231
62196232
"""
62206233
warnings.warn(
6221-
"accessing GroupBy by index is deprecated, consider using the `.agg` method",
6234+
"accessing GroupBy by index is deprecated, consider using the `.agg`"
6235+
" method",
62226236
DeprecationWarning,
62236237
)
62246238
return self._dataframe_class._from_pydf(
@@ -6377,11 +6391,13 @@ def _wrangle(x: Any) -> list:
63776391
)
63786392
else:
63796393
raise ValueError(
6380-
f"argument: {column_to_agg} not understood, have you passed a list of expressions?"
6394+
f"argument: {column_to_agg} not understood, have you passed a list"
6395+
" of expressions?"
63816396
)
63826397
else:
63836398
raise ValueError(
6384-
f"argument: {column_to_agg} not understood, have you passed a list of expressions?"
6399+
f"argument: {column_to_agg} not understood, have you passed a list of"
6400+
" expressions?"
63856401
)
63866402

63876403
return self._dataframe_class._from_pydf(

py-polars/polars/internals/lazy_frame.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ def _scan_python_function(
360360
def __getitem__(self: LDF, item: int | range | slice) -> LazyFrame:
361361
if not isinstance(item, slice):
362362
raise TypeError(
363-
"'LazyFrame' object is not subscriptable (aside from slicing). Use 'select()' or 'filter()' instead."
363+
"'LazyFrame' object is not subscriptable (aside from slicing). Use"
364+
" 'select()' or 'filter()' instead."
364365
)
365366
return LazyPolarsSlice(self).apply(item)
366367

@@ -411,7 +412,10 @@ def _repr_html_(self) -> str:
411412
svg = subprocess.check_output(
412413
["dot", "-Nshape=box", "-Tsvg"], input=f"{dot}".encode()
413414
)
414-
return f"<h4>NAIVE QUERY PLAN</h4><p>run <b>LazyFrame.show_graph()</b> to see the optimized version</p>{svg.decode()}"
415+
return (
416+
"<h4>NAIVE QUERY PLAN</h4><p>run <b>LazyFrame.show_graph()</b> to see"
417+
f" the optimized version</p>{svg.decode()}"
418+
)
415419
except Exception:
416420
insert = self.describe_plan().replace("\n", "<p></p>")
417421

@@ -491,14 +495,16 @@ def show_graph(
491495
return display(SVG(svg))
492496
except Exception as exc:
493497
raise ImportError(
494-
"Graphviz dot binary should be on your PATH and matplotlib should be installed to show graph."
498+
"Graphviz dot binary should be on your PATH and matplotlib should"
499+
" be installed to show graph."
495500
) from exc
496501
try:
497502
import matplotlib.image as mpimg
498503
import matplotlib.pyplot as plt
499504
except ImportError:
500505
raise ImportError(
501-
"Graphviz dot binary should be on your PATH and matplotlib should be installed to show graph."
506+
"Graphviz dot binary should be on your PATH and matplotlib should be"
507+
" installed to show graph."
502508
) from None
503509
dot = self._ldf.to_dot(optimized)
504510
if raw_output:
@@ -1404,7 +1410,8 @@ def join(
14041410

14051411
if how == "asof":
14061412
warnings.warn(
1407-
"using asof join via LazyFrame.join is deprecated, please use LazyFrame.join_asof",
1413+
"using asof join via LazyFrame.join is deprecated, please use"
1414+
" LazyFrame.join_asof",
14081415
DeprecationWarning,
14091416
)
14101417
if how == "cross":
@@ -1567,7 +1574,8 @@ def with_columns(
15671574
"""
15681575
if named_exprs and not Config.with_columns_kwargs:
15691576
raise RuntimeError(
1570-
"**kwargs support is experimental; requires opt-in via `pl.Config.set_with_columns_kwargs(True)`"
1577+
"**kwargs support is experimental; requires opt-in via"
1578+
" `pl.Config.set_with_columns_kwargs(True)`"
15711579
)
15721580
elif exprs is None and not named_exprs:
15731581
raise ValueError("Expected at least one of 'exprs' or **named_exprs")

py-polars/polars/internals/lazy_functions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,8 @@ def arg_where(
17531753
if eager:
17541754
if not isinstance(condition, pli.Series):
17551755
raise ValueError(
1756-
f"expected 'Series' in 'arg_where' if 'eager=True', got {type(condition)}"
1756+
"expected 'Series' in 'arg_where' if 'eager=True', got"
1757+
f" {type(condition)}"
17571758
)
17581759
return (
17591760
condition.to_frame().select(arg_where(pli.col(condition.name))).to_series()

py-polars/polars/internals/series.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ def _arithmetic(self, other: Any, op_s: str, op_ffi: str) -> Series:
359359
f = get_ffi_func(op_ffi, self.dtype, self._s)
360360
if f is None:
361361
raise ValueError(
362-
f"cannot do arithmetic with series of dtype: {self.dtype} and argument of type: {type(other)}"
362+
f"cannot do arithmetic with series of dtype: {self.dtype} and argument"
363+
f" of type: {type(other)}"
363364
)
364365
return wrap_s(f(other))
365366

@@ -495,7 +496,8 @@ def __setitem__(
495496
self.set_at_idx(key, value) # type: ignore[arg-type]
496497
return None
497498
raise ValueError(
498-
f"cannot set Series of dtype: {self.dtype} with list/tuple as value; use a scalar value"
499+
f"cannot set Series of dtype: {self.dtype} with list/tuple as value;"
500+
" use a scalar value"
499501
)
500502
if isinstance(key, Series):
501503
if key.dtype == Boolean:
@@ -2260,7 +2262,8 @@ def __array_ufunc__(
22602262
return wrap_s(series)
22612263
else:
22622264
raise NotImplementedError(
2263-
f"Only `__call__` is implemented for numpy ufuncs on a Series, got `{method}`."
2265+
"Only `__call__` is implemented for numpy ufuncs on a Series, got"
2266+
f" `{method}`."
22642267
)
22652268

22662269
def to_numpy(
@@ -2344,7 +2347,8 @@ def to_pandas(self) -> pd.Series:
23442347
"""
23452348
if not _PYARROW_AVAILABLE: # pragma: no cover
23462349
raise ImportError(
2347-
"'pyarrow' is required for converting a 'polars' Series to a 'pandas' Series."
2350+
"'pyarrow' is required for converting a 'polars' Series to a 'pandas'"
2351+
" Series."
23482352
)
23492353
return self.to_arrow().to_pandas()
23502354

@@ -2419,7 +2423,8 @@ def set_at_idx(
24192423
f = get_ffi_func("set_at_idx_<>", self.dtype, self._s)
24202424
if f is None:
24212425
raise ValueError(
2422-
f"could not find the FFI function needed to set at idx for series {self._s}"
2426+
"could not find the FFI function needed to set at idx for series"
2427+
f" {self._s}"
24232428
)
24242429
if isinstance(idx, Series):
24252430
# make sure the dtype matches

py-polars/polars/internals/slice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,5 @@ def apply(self, s: slice) -> "pli.LazyFrame":
205205

206206
raise ValueError(
207207
f"The given slice {s} is not supported by lazy computation; consider a "
208-
f"more efficient approach, or construct explicitly with other methods"
208+
"more efficient approach, or construct explicitly with other methods"
209209
)

py-polars/polars/io.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ def _check_arg_is_1byte(
3939
if can_be_empty:
4040
if arg_byte_length > 1:
4141
raise ValueError(
42-
f'{arg_name}="{arg}" should be a single byte character or empty, but is {arg_byte_length} bytes long.'
42+
f'{arg_name}="{arg}" should be a single byte character or empty,'
43+
f" but is {arg_byte_length} bytes long."
4344
)
4445
elif arg_byte_length != 1:
4546
raise ValueError(
46-
f'{arg_name}="{arg}" should be a single byte character, but is {arg_byte_length} bytes long.'
47+
f'{arg_name}="{arg}" should be a single byte character, but is'
48+
f" {arg_byte_length} bytes long."
4749
)
4850

4951

@@ -305,7 +307,8 @@ def read_csv(
305307
if columns:
306308
if len(columns) < len(new_columns):
307309
raise ValueError(
308-
"More new column names are specified than there are selected columns."
310+
"More new column names are specified than there are selected"
311+
" columns."
309312
)
310313

311314
# Get column names of requested columns.
@@ -316,7 +319,8 @@ def read_csv(
316319
if projection:
317320
if columns and len(columns) < len(new_columns):
318321
raise ValueError(
319-
"More new column names are specified than there are selected columns."
322+
"More new column names are specified than there are selected"
323+
" columns."
320324
)
321325
# Convert column indices from projection to 'column_1', 'column_2', ... column names.
322326
current_columns = [
@@ -770,7 +774,8 @@ def read_ipc(
770774
if use_pyarrow:
771775
if not _PYARROW_AVAILABLE:
772776
raise ImportError(
773-
"'pyarrow' is required when using 'read_ipc(..., use_pyarrow=True)'."
777+
"'pyarrow' is required when using"
778+
" 'read_ipc(..., use_pyarrow=True)'."
774779
)
775780

776781
tbl = pa.feather.read_table(data, memory_map=memory_map, columns=columns)
@@ -851,7 +856,8 @@ def read_parquet(
851856
if use_pyarrow:
852857
if not _PYARROW_AVAILABLE:
853858
raise ImportError(
854-
"'pyarrow' is required when using 'read_parquet(..., use_pyarrow=True)'."
859+
"'pyarrow' is required when using"
860+
" 'read_parquet(..., use_pyarrow=True)'."
855861
)
856862

857863
return from_arrow( # type: ignore[return-value]

py-polars/polars/testing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ def __post_init__(self) -> None:
402402
self.null_probability < 0 or self.null_probability > 1
403403
):
404404
raise InvalidArgument(
405-
f"null_probability should be between 0.0 and 1.0, or None; found {self.null_probability}"
405+
"null_probability should be between 0.0 and 1.0, or None; found"
406+
f" {self.null_probability}"
406407
)
407408
if self.dtype is None and not self.strategy:
408409
self.dtype = random.choice(strategy_dtypes)
@@ -590,7 +591,8 @@ def series(
590591
]
591592
if null_probability and (null_probability < 0 or null_probability > 1):
592593
raise InvalidArgument(
593-
f"null_probability should be between 0.0 and 1.0; found {null_probability}"
594+
"null_probability should be between 0.0 and 1.0; found"
595+
f" {null_probability}"
594596
)
595597
null_probability = float(null_probability or 0.0)
596598

py-polars/polars/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def handle_projection_columns(
152152
columns = None
153153
elif not is_str_sequence(columns):
154154
raise ValueError(
155-
"columns arg should contain a list of all integers or all strings values."
155+
"columns arg should contain a list of all integers or all strings"
156+
" values."
156157
)
157158
return projection, columns # type: ignore[return-value]
158159

0 commit comments

Comments
 (0)