Skip to content

Commit e7252b8

Browse files
committed
Ruff lints
1 parent 467fde1 commit e7252b8

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/nested_pandas/nestedframe/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def from_lists(cls, df, base_columns=None, list_columns=None, name="nested"):
538538
# This is a simple heuristic but infers more than its dtype
539539
# which will probably be an object.
540540
sample_val = df[col].iloc[0]
541-
if not hasattr(sample_val, "__iter__") and not isinstance(sample_val, (str, bytes)):
541+
if not hasattr(sample_val, "__iter__") and not isinstance(sample_val, str | bytes):
542542
raise ValueError(
543543
f"Cannot pack column {col} which does not contain an iterable list based "
544544
"on its first value, {sample_val}."
@@ -1290,7 +1290,7 @@ def reduce(self, func, *args, infer_nesting=True, **kwargs) -> NestedFrame: # t
12901290
else:
12911291
iterators.append(self[layer].array.iter_field_lists(col))
12921292

1293-
results = [func(*cols, *extra_args, **kwargs) for cols in zip(*iterators)]
1293+
results = [func(*cols, *extra_args, **kwargs) for cols in zip(*iterators, strict=True)]
12941294
results_nf = NestedFrame(results, index=self.index)
12951295

12961296
if infer_nesting:

src/nested_pandas/nestedframe/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def read_parquet(
8787
# First load through pyarrow
8888
# Check if `data` is a file-like object or a sequence
8989
if hasattr(data, "read") or (
90-
isinstance(data, Sequence) and not isinstance(data, (str, bytes, bytearray))
90+
isinstance(data, Sequence) and not isinstance(data, str | bytes | bytearray)
9191
):
9292
# If `data` is a file-like object or a sequence, pass it directly to pyarrow
9393
table = pq.read_table(data, columns=columns, **kwargs)
@@ -103,7 +103,7 @@ def read_parquet(
103103
# was from a nested column.
104104
if columns is not None:
105105
nested_structures: dict[str, list[int]] = {}
106-
for i, (col_in, col_pa) in enumerate(zip(columns, table.column_names)):
106+
for i, (col_in, col_pa) in enumerate(zip(columns, table.column_names, strict=True)):
107107
# if the column name is not the same, it was a partial load
108108
if col_in != col_pa:
109109
# get the top-level column name

src/nested_pandas/series/ext_array.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
# typing.Self and "|" union syntax don't exist in Python 3.9
3636
from __future__ import annotations
3737

38-
from collections.abc import Generator, Iterable, Iterator, Sequence
39-
from typing import Any, Callable, cast
38+
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
39+
from typing import Any, cast
4040

4141
import numpy as np
4242
import pandas as pd
@@ -551,7 +551,7 @@ def format_series(series):
551551
return series.apply(repr)
552552

553553
def format_row(row):
554-
return ", ".join(f"{name}: {value}" for name, value in zip(row.index, row))
554+
return ", ".join(f"{name}: {value}" for name, value in zip(row.index, row, strict=True))
555555

556556
# Format series to strings
557557
df = df.apply(format_series, axis=0)
@@ -665,7 +665,7 @@ def _box_pa_array(cls, value, *, pa_type: pa.DataType | None) -> pa.Array | pa.C
665665
"""Convert a value to a PyArrow array with the specified type."""
666666
if isinstance(value, cls):
667667
pa_array = value.struct_array
668-
elif isinstance(value, (pa.Array, pa.ChunkedArray)):
668+
elif isinstance(value, pa.Array | pa.ChunkedArray):
669669
pa_array = value
670670
else:
671671
try:
@@ -700,7 +700,7 @@ def _from_arrow_like(cls, arraylike, dtype: NestedDtype | None = None) -> Self:
700700
if dtype is None or dtype == arraylike.dtype:
701701
return arraylike
702702
array = arraylike.list_array
703-
elif isinstance(arraylike, (pa.Array, pa.ChunkedArray)):
703+
elif isinstance(arraylike, pa.Array | pa.ChunkedArray):
704704
array = arraylike
705705
else:
706706
array = pa.array(arraylike)
@@ -1112,7 +1112,7 @@ def fill_field_lists(self, field: str, value: ArrayLike, *, keep_dtype: bool = F
11121112
)
11131113
if np.size(value) != len(self):
11141114
raise ValueError("The length of the input array must be equal to the length of the series")
1115-
if isinstance(value, (pa.ChunkedArray, pa.Array)):
1115+
if isinstance(value, pa.ChunkedArray | pa.Array):
11161116
value = pa.compute.take(value, self.get_list_index())
11171117
else:
11181118
value = np.repeat(value, self.list_lengths)

tests/nested_pandas/series/test_ext_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,9 +1375,9 @@ def test_iter_field_lists():
13751375
)
13761376
ext_array = NestedExtensionArray(struct_array)
13771377

1378-
for actual, desired in zip(ext_array.iter_field_lists("a"), a):
1378+
for actual, desired in zip(ext_array.iter_field_lists("a"), a, strict=True):
13791379
assert_array_equal(actual, desired)
1380-
for actual, desired in zip(ext_array.iter_field_lists("b"), b):
1380+
for actual, desired in zip(ext_array.iter_field_lists("b"), b, strict=True):
13811381
assert_array_equal(actual, desired)
13821382

13831383

0 commit comments

Comments
 (0)