Skip to content

Commit ca8d63f

Browse files
authored
chore: bump pyarrow-stubs==19.1 (#2350)
* ci: bump `pyarrow-stubs==17.19` * chore(typing): Add new type ignores Quite a few are fixed by zen-xu/pyarrow-stubs#196 * fix(typing): Use `lit` to match overloads * chore: bump `pyarrow-stubs==19.1` Lots of fixes from zen-xu/pyarrow-stubs#196 * fix(typing): Resolve `[assignment]`
1 parent 4040065 commit ca8d63f

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

narwhals/_arrow/series.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ def __narwhals_namespace__(self: Self) -> ArrowNamespace:
191191

192192
def __eq__(self: Self, other: object) -> Self: # type: ignore[override]
193193
ser, other = extract_native(self, other)
194-
return self._with_native(pc.equal(ser, other)) # type: ignore[arg-type]
194+
return self._with_native(pc.equal(ser, other)) # type: ignore[call-overload]
195195

196196
def __ne__(self: Self, other: object) -> Self: # type: ignore[override]
197197
ser, other = extract_native(self, other)
198-
return self._with_native(pc.not_equal(ser, other)) # type: ignore[arg-type]
198+
return self._with_native(pc.not_equal(ser, other)) # type: ignore[call-overload]
199199

200200
def __ge__(self: Self, other: Any) -> Self:
201201
ser, other = extract_native(self, other)
@@ -271,14 +271,14 @@ def __truediv__(self: Self, other: Any) -> Self:
271271
if not isinstance(other, (pa.Array, pa.ChunkedArray)):
272272
# scalar
273273
other = lit(other)
274-
return self._with_native(pc.divide(*cast_for_truediv(ser, other)))
274+
return self._with_native(pc.divide(*cast_for_truediv(ser, other))) # type: ignore[arg-type, type-var]
275275

276276
def __rtruediv__(self: Self, other: Any) -> Self:
277277
ser, other = extract_native(self, other)
278278
if not isinstance(other, (pa.Array, pa.ChunkedArray)):
279279
# scalar
280280
other = lit(other) if not isinstance(other, pa.Scalar) else other
281-
return self._with_native(pc.divide(*cast_for_truediv(other, ser))) # pyright: ignore[reportArgumentType]
281+
return self._with_native(pc.divide(*cast_for_truediv(other, ser))) # type: ignore[arg-type, type-var]
282282

283283
def __mod__(self: Self, other: Any) -> Self:
284284
floor_div = (self // other).native
@@ -596,11 +596,11 @@ def value_counts(
596596
counts = cast("ArrowChunkedArray", val_counts.field("counts"))
597597

598598
if normalize:
599-
arrays = [values, pc.divide(*cast_for_truediv(counts, pc.sum(counts)))]
599+
arrays = [values, pc.divide(*cast_for_truediv(counts, pc.sum(counts)))] # type: ignore[type-var]
600600
else:
601601
arrays = [values, counts]
602602

603-
val_count = pa.Table.from_arrays(arrays, names=[index_name_, value_name_])
603+
val_count = pa.Table.from_arrays(arrays, names=[index_name_, value_name_]) # type: ignore[arg-type]
604604

605605
if sort:
606606
val_count = val_count.sort_by([(value_name_, "descending")])
@@ -662,7 +662,7 @@ def fill_aux(
662662
)[::-1]
663663
distance = valid_index - indices
664664
return pc.if_else(
665-
pc.and_(pc.is_null(arr), pc.less_equal(distance, lit(limit))),
665+
pc.and_(pc.is_null(arr), pc.less_equal(distance, lit(limit))), # pyright: ignore[reportArgumentType, reportCallIssue]
666666
arr.take(valid_index),
667667
arr,
668668
)
@@ -1041,8 +1041,6 @@ def rank(
10411041
)
10421042
raise ValueError(msg)
10431043

1044-
# ignore-banned-import
1045-
10461044
sort_keys: Order = "descending" if descending else "ascending"
10471045
tiebreaker: TieBreaker = "first" if method == "ordinal" else method
10481046

@@ -1078,7 +1076,7 @@ def _hist_from_bin_count(bin_count: int): # type: ignore[no-untyped-def] # noqa
10781076
lower, upper = d["min"], d["max"]
10791077
pa_float = pa.type_for_alias("float")
10801078
if lower == upper:
1081-
range_ = lit(1.0)
1079+
range_: pa.Scalar[Any] = lit(1.0)
10821080
mid = lit(0.5)
10831081
width = pc.divide(range_, lit(bin_count))
10841082
lower = pc.subtract(lower, mid)
@@ -1094,9 +1092,9 @@ def _hist_from_bin_count(bin_count: int): # type: ignore[no-untyped-def] # noqa
10941092
bin_indices = pc.if_else(
10951093
pc.and_(
10961094
pc.equal(bin_indices, bin_proportions),
1097-
pc.greater(bin_indices, 0),
1095+
pc.greater(bin_indices, lit(0)),
10981096
),
1099-
pc.subtract(bin_indices, 1),
1097+
pc.subtract(bin_indices, lit(1)),
11001098
bin_indices,
11011099
)
11021100
possible = pa.Table.from_arrays(

narwhals/_arrow/series_dt.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from typing_extensions import Self
1717

1818
from narwhals._arrow.series import ArrowSeries
19-
from narwhals._arrow.typing import ArrowChunkedArray
2019
from narwhals.dtypes import Datetime
2120
from narwhals.typing import TimeUnit
2221

@@ -56,47 +55,48 @@ def timestamp(self: Self, time_unit: TimeUnit) -> ArrowSeries:
5655
s_cast = self.native.cast(pa.int64())
5756
if unit == "ns":
5857
if time_unit == "ns":
59-
result = s_cast
58+
result_64 = s_cast
6059
elif time_unit == "us":
61-
result = floordiv_compat(s_cast, 1_000)
60+
result_64 = floordiv_compat(s_cast, 1_000)
6261
else:
63-
result = floordiv_compat(s_cast, 1_000_000)
62+
result_64 = floordiv_compat(s_cast, 1_000_000)
6463
elif unit == "us":
6564
if time_unit == "ns":
66-
result = cast("ArrowChunkedArray", pc.multiply(s_cast, 1_000))
65+
result_64 = pc.multiply(s_cast, lit(1_000))
6766
elif time_unit == "us":
68-
result = s_cast
67+
result_64 = s_cast
6968
else:
70-
result = floordiv_compat(s_cast, 1_000)
69+
result_64 = floordiv_compat(s_cast, 1_000)
7170
elif unit == "ms":
7271
if time_unit == "ns":
73-
result = cast("ArrowChunkedArray", pc.multiply(s_cast, 1_000_000))
72+
result_64 = pc.multiply(s_cast, lit(1_000_000))
7473
elif time_unit == "us":
75-
result = cast("ArrowChunkedArray", pc.multiply(s_cast, 1_000))
74+
result_64 = pc.multiply(s_cast, lit(1_000))
7675
else:
77-
result = s_cast
76+
result_64 = s_cast
7877
elif unit == "s":
7978
if time_unit == "ns":
80-
result = cast("ArrowChunkedArray", pc.multiply(s_cast, 1_000_000_000))
79+
result_64 = pc.multiply(s_cast, lit(1_000_000_000))
8180
elif time_unit == "us":
82-
result = cast("ArrowChunkedArray", pc.multiply(s_cast, 1_000_000))
81+
result_64 = pc.multiply(s_cast, lit(1_000_000))
8382
else:
84-
result = cast("ArrowChunkedArray", pc.multiply(s_cast, 1_000))
83+
result_64 = pc.multiply(s_cast, lit(1_000))
8584
else: # pragma: no cover
8685
msg = f"unexpected time unit {unit}, please report an issue at https://github.com/narwhals-dev/narwhals"
8786
raise AssertionError(msg)
87+
return self.with_native(result_64)
8888
elif isinstance(ser.dtype, dtypes.Date):
89-
time_s = pc.multiply(self.native.cast(pa.int32()), 86400)
89+
time_s = pc.multiply(self.native.cast(pa.int32()), lit(86_400))
9090
if time_unit == "ns":
91-
result = cast("ArrowChunkedArray", pc.multiply(time_s, 1_000_000_000))
91+
result_32 = pc.multiply(time_s, lit(1_000_000_000))
9292
elif time_unit == "us":
93-
result = cast("ArrowChunkedArray", pc.multiply(time_s, 1_000_000))
93+
result_32 = pc.multiply(time_s, lit(1_000_000))
9494
else:
95-
result = cast("ArrowChunkedArray", pc.multiply(time_s, 1_000))
95+
result_32 = pc.multiply(time_s, lit(1_000))
96+
return self.with_native(result_32)
9697
else:
9798
msg = "Input should be either of Date or Datetime type"
9899
raise TypeError(msg)
99-
return self.with_native(result)
100100

101101
def date(self: Self) -> ArrowSeries:
102102
return self.with_native(self.native.cast(pa.date32()))

narwhals/_pandas_like/series_dt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ def microsecond(self) -> PandasLikeSeries:
5858
# crazy workaround for https://github.com/pandas-dev/pandas/issues/59154
5959
import pyarrow.compute as pc # ignore-banned-import()
6060

61+
from narwhals._arrow.utils import lit
62+
6163
arr_ns = self.native.array
6264
arr = arr_ns.__arrow_array__()
6365
result_arr = pc.add(
64-
pc.multiply(pc.millisecond(arr), 1000), pc.microsecond(arr)
66+
pc.multiply(pc.millisecond(arr), lit(1_000)), pc.microsecond(arr)
6567
)
6668
result = type(self.native)(type(arr_ns)(result_arr), name=self.native.name)
6769
return self.with_native(result)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typing = [
6767
"typing_extensions",
6868
"mypy~=1.15.0",
6969
"pyright",
70-
"pyarrow-stubs==17.18",
70+
"pyarrow-stubs==19.1",
7171
"sqlframe",
7272
"polars==1.25.2",
7373
"uv",

0 commit comments

Comments
 (0)