Skip to content

Commit 84473e3

Browse files
committed
Merge remote-tracking branch 'upstream/main' into oh-nodes
2 parents be6ec3e + 43d206c commit 84473e3

File tree

172 files changed

+1152
-2739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+1152
-2739
lines changed

narwhals/_arrow/dataframe.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def join(
431431
join_type=how_to_join_map[how],
432432
right_suffix=suffix,
433433
coalesce_keys=coalesce_keys,
434-
),
434+
)
435435
)
436436

437437
join_asof = not_implemented()
@@ -448,12 +448,7 @@ def drop_nulls(self: ArrowDataFrame, subset: Sequence[str] | None) -> ArrowDataF
448448
plx = self.__narwhals_namespace__()
449449
return self.filter(~plx.any_horizontal(plx.col(*subset).is_null()))
450450

451-
def sort(
452-
self,
453-
*by: str,
454-
descending: bool | Sequence[bool],
455-
nulls_last: bool,
456-
) -> Self:
451+
def sort(self, *by: str, descending: bool | Sequence[bool], nulls_last: bool) -> Self:
457452
if isinstance(descending, bool):
458453
order: Order = "descending" if descending else "ascending"
459454
sorting: list[tuple[str, Order]] = [(key, order) for key in by]

narwhals/_arrow/group_by.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ def __iter__(self) -> Iterator[tuple[Any, ArrowDataFrame]]:
148148
# Reality: `str` is fine
149149
concat_str: Incomplete = pc.binary_join_element_wise
150150
key_values = concat_str(
151-
*it,
152-
separator_scalar,
153-
null_handling="replace",
154-
null_replacement=null_token,
151+
*it, separator_scalar, null_handling="replace", null_replacement=null_token
155152
)
156153
table = table.add_column(i=0, field_=col_token, column=key_values)
157154

narwhals/_arrow/namespace.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ def when(self, predicate: ArrowExpr) -> ArrowWhen:
234234
return ArrowWhen.from_expr(predicate, context=self)
235235

236236
def concat_str(
237-
self,
238-
*exprs: ArrowExpr,
239-
separator: str,
240-
ignore_nulls: bool,
237+
self, *exprs: ArrowExpr, separator: str, ignore_nulls: bool
241238
) -> ArrowExpr:
242239
def func(df: ArrowDataFrame) -> list[ArrowSeries]:
243240
compliant_series_list = align_series_full_broadcast(

narwhals/_arrow/series.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,7 @@ def item(self, index: int | None = None) -> Any:
587587
return maybe_extract_py_scalar(self.native[index], return_py_scalar=True)
588588

589589
def value_counts(
590-
self,
591-
*,
592-
sort: bool,
593-
parallel: bool,
594-
name: str | None,
595-
normalize: bool,
590+
self, *, sort: bool, parallel: bool, name: str | None, normalize: bool
596591
) -> ArrowDataFrame:
597592
"""Parallel is unused, exists for compatibility."""
598593
from narwhals._arrow.dataframe import ArrowDataFrame

narwhals/_arrow/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def is_duration(t: Any) -> TypeIs[pa.DurationType[Any]]: ...
4242
def is_list(t: Any) -> TypeIs[pa.ListType[Any]]: ...
4343
def is_large_list(t: Any) -> TypeIs[pa.LargeListType[Any]]: ...
4444
def is_fixed_size_list(t: Any) -> TypeIs[pa.FixedSizeListType[Any, Any]]: ...
45-
def is_dictionary(
46-
t: Any,
47-
) -> TypeIs[pa.DictionaryType[Any, Any, Any]]: ...
45+
def is_dictionary(t: Any) -> TypeIs[pa.DictionaryType[Any, Any, Any]]: ...
4846
def extract_regex(
4947
strings: ChunkedArrayAny,
5048
/,

narwhals/_compliant/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
from narwhals._translate import NumpyConvertible
2727
from narwhals._translate import ToNarwhals
2828
from narwhals._translate import ToNarwhalsT_co
29+
from narwhals._typing_compat import deprecated
2930
from narwhals.utils import Version
3031
from narwhals.utils import _StoresNative
31-
from narwhals.utils import deprecated
3232
from narwhals.utils import is_compliant_series
3333
from narwhals.utils import is_index_selector
3434
from narwhals.utils import is_range

narwhals/_compliant/expr.py

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import sys
43
from functools import partial
54
from operator import methodcaller
65
from typing import TYPE_CHECKING
@@ -30,23 +29,14 @@
3029
from narwhals._compliant.typing import EagerSeriesT
3130
from narwhals._compliant.typing import LazyExprT
3231
from narwhals._compliant.typing import NativeExprT
32+
from narwhals._typing_compat import Protocol38
33+
from narwhals._typing_compat import deprecated
3334
from narwhals.dependencies import get_numpy
3435
from narwhals.dependencies import is_numpy_array
3536
from narwhals.dtypes import DType
3637
from narwhals.utils import _StoresCompliant
37-
from narwhals.utils import deprecated
3838
from narwhals.utils import not_implemented
3939

40-
if not TYPE_CHECKING: # pragma: no cover
41-
if sys.version_info >= (3, 9):
42-
from typing import Protocol as Protocol38
43-
else:
44-
from typing import Generic as Protocol38
45-
else: # pragma: no cover
46-
# TODO @dangotbanned: Remove after dropping `3.8` (#2084)
47-
# - https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386
48-
from typing import Protocol as Protocol38
49-
5040
if TYPE_CHECKING:
5141
from typing import Mapping
5242

@@ -214,37 +204,19 @@ def ewm_mean(
214204
) -> Self: ...
215205

216206
def rolling_sum(
217-
self,
218-
window_size: int,
219-
*,
220-
min_samples: int,
221-
center: bool,
207+
self, window_size: int, *, min_samples: int, center: bool
222208
) -> Self: ...
223209

224210
def rolling_mean(
225-
self,
226-
window_size: int,
227-
*,
228-
min_samples: int,
229-
center: bool,
211+
self, window_size: int, *, min_samples: int, center: bool
230212
) -> Self: ...
231213

232214
def rolling_var(
233-
self,
234-
window_size: int,
235-
*,
236-
min_samples: int,
237-
center: bool,
238-
ddof: int,
215+
self, window_size: int, *, min_samples: int, center: bool, ddof: int
239216
) -> Self: ...
240217

241218
def rolling_std(
242-
self,
243-
window_size: int,
244-
*,
245-
min_samples: int,
246-
center: bool,
247-
ddof: int,
219+
self, window_size: int, *, min_samples: int, center: bool, ddof: int
248220
) -> Self: ...
249221

250222
@deprecated("Since `1.22.0`")
@@ -831,9 +803,7 @@ def rolling_var(
831803
)
832804

833805
def map_batches(
834-
self,
835-
function: Callable[[Any], Any],
836-
return_dtype: DType | type[DType] | None,
806+
self, function: Callable[[Any], Any], return_dtype: DType | type[DType] | None
837807
) -> Self:
838808
def func(df: EagerDataFrameT) -> Sequence[EagerSeriesT]:
839809
input_series_list = self(df)

narwhals/_compliant/group_by.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import re
4-
import sys
54
from typing import TYPE_CHECKING
65
from typing import Any
76
from typing import Callable
@@ -26,6 +25,7 @@
2625
from narwhals._compliant.typing import EagerExprT_contra
2726
from narwhals._compliant.typing import LazyExprT_contra
2827
from narwhals._compliant.typing import NativeExprT_co
28+
from narwhals._typing_compat import Protocol38
2929
from narwhals.utils import is_sequence_of
3030

3131
if TYPE_CHECKING:
@@ -34,16 +34,6 @@
3434
_SameFrameT = TypeVar("_SameFrameT", CompliantDataFrameAny, CompliantLazyFrameAny)
3535

3636

37-
if not TYPE_CHECKING: # pragma: no cover
38-
if sys.version_info >= (3, 9):
39-
from typing import Protocol as Protocol38
40-
else:
41-
from typing import Generic as Protocol38
42-
else: # pragma: no cover
43-
# TODO @dangotbanned: Remove after dropping `3.8` (#2084)
44-
# - https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386
45-
from typing import Protocol as Protocol38
46-
4737
__all__ = [
4838
"CompliantGroupBy",
4939
"DepthTrackingGroupBy",

narwhals/_compliant/namespace.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ def when(
8484
self, predicate: CompliantExprT
8585
) -> CompliantWhen[CompliantFrameT, Incomplete, CompliantExprT]: ...
8686
def concat_str(
87-
self,
88-
*exprs: CompliantExprT,
89-
separator: str,
90-
ignore_nulls: bool,
87+
self, *exprs: CompliantExprT, separator: str, ignore_nulls: bool
9188
) -> CompliantExprT: ...
9289
@property
9390
def selectors(self) -> CompliantSelectorNamespace[Any, Any]: ...
@@ -167,12 +164,7 @@ def from_native(
167164
raise TypeError(msg)
168165

169166
@overload
170-
def from_numpy(
171-
self,
172-
data: Into1DArray,
173-
/,
174-
schema: None = ...,
175-
) -> EagerSeriesT: ...
167+
def from_numpy(self, data: Into1DArray, /, schema: None = ...) -> EagerSeriesT: ...
176168

177169
@overload
178170
def from_numpy(

narwhals/_compliant/selectors.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,12 @@
1414
from typing import overload
1515

1616
from narwhals._compliant.expr import CompliantExpr
17+
from narwhals._typing_compat import Protocol38
1718
from narwhals.utils import _parse_time_unit_and_time_zone
1819
from narwhals.utils import dtype_matches_time_unit_and_time_zone
1920
from narwhals.utils import get_column_names
2021
from narwhals.utils import is_compliant_dataframe
2122

22-
if not TYPE_CHECKING: # pragma: no cover
23-
# TODO @dangotbanned: Remove after dropping `3.8` (#2084)
24-
# - https://github.com/narwhals-dev/narwhals/pull/2064#discussion_r1965921386
25-
import sys
26-
27-
if sys.version_info >= (3, 9):
28-
from typing import Protocol as Protocol38
29-
else:
30-
from typing import Generic as Protocol38
31-
32-
else: # pragma: no cover
33-
from typing import Protocol as Protocol38
34-
3523
if TYPE_CHECKING:
3624
from datetime import timezone
3725

0 commit comments

Comments
 (0)