Skip to content

Commit d395e1e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into refac-native-module
2 parents 16b0074 + e9841e0 commit d395e1e

File tree

2 files changed

+7
-89
lines changed

2 files changed

+7
-89
lines changed

narwhals/_compliant/dataframe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class CompliantFrame(
9999

100100
def __native_namespace__(self) -> ModuleType: ...
101101
def __narwhals_namespace__(self) -> Any: ...
102+
def _with_native(self, df: _NativeFrameT) -> Self: ...
102103
def _with_version(self, version: Version) -> Self: ...
103104
@classmethod
104105
def from_native(cls, data: _NativeFrameT, /, *, context: _LimitedContext) -> Self: ...

narwhals/_utils.py

Lines changed: 6 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@
146146
_T1 = TypeVar("_T1")
147147
_T2 = TypeVar("_T2")
148148
_T3 = TypeVar("_T3")
149-
_T4 = TypeVar("_T4")
150-
_T5 = TypeVar("_T5")
151-
_T6 = TypeVar("_T6")
152-
_T7 = TypeVar("_T7")
153149
_Fn = TypeVar("_Fn", bound="Callable[..., Any]")
154150
P = ParamSpec("P")
155151
R = TypeVar("R")
@@ -748,76 +744,6 @@ def isinstance_or_issubclass(
748744
) -> TypeIs[_T1 | _T2 | _T3 | type[_T1 | _T2 | _T3]]: ...
749745

750746

751-
@overload
752-
def isinstance_or_issubclass(
753-
obj_or_cls: type, cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4]]
754-
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4]]: ...
755-
756-
757-
@overload
758-
def isinstance_or_issubclass(
759-
obj_or_cls: object | type,
760-
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4]],
761-
) -> TypeIs[_T1 | _T2 | _T3 | _T4 | type[_T1 | _T2 | _T3 | _T4]]: ...
762-
763-
764-
@overload
765-
def isinstance_or_issubclass(
766-
obj_or_cls: type,
767-
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5]],
768-
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5]]: ...
769-
770-
771-
@overload
772-
def isinstance_or_issubclass(
773-
obj_or_cls: object | type,
774-
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5]],
775-
) -> TypeIs[_T1 | _T2 | _T3 | _T4 | _T5 | type[_T1 | _T2 | _T3 | _T4 | _T5]]: ...
776-
777-
778-
@overload
779-
def isinstance_or_issubclass(
780-
obj_or_cls: type,
781-
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6]],
782-
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6]]: ...
783-
784-
785-
@overload
786-
def isinstance_or_issubclass(
787-
obj_or_cls: object | type,
788-
cls_or_tuple: tuple[type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6]],
789-
) -> TypeIs[
790-
_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6]
791-
]: ...
792-
793-
794-
@overload
795-
def isinstance_or_issubclass(
796-
obj_or_cls: type,
797-
cls_or_tuple: tuple[
798-
type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6], type[_T7]
799-
],
800-
) -> TypeIs[type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | _T7]]: ...
801-
802-
803-
@overload
804-
def isinstance_or_issubclass(
805-
obj_or_cls: object | type,
806-
cls_or_tuple: tuple[
807-
type[_T1], type[_T2], type[_T3], type[_T4], type[_T5], type[_T6], type[_T7]
808-
],
809-
) -> TypeIs[
810-
_T1
811-
| _T2
812-
| _T3
813-
| _T4
814-
| _T5
815-
| _T6
816-
| _T7
817-
| type[_T1 | _T2 | _T3 | _T4 | _T5 | _T6 | _T7]
818-
]: ...
819-
820-
821747
@overload
822748
def isinstance_or_issubclass(
823749
obj_or_cls: Any, cls_or_tuple: tuple[type, ...]
@@ -1207,21 +1133,12 @@ def maybe_convert_dtypes(
12071133
b boolean
12081134
dtype: object
12091135
"""
1210-
obj_any = cast("Any", obj)
1211-
native_obj = obj_any.to_native()
1212-
if is_pandas_like_dataframe(native_obj):
1213-
return obj_any._with_compliant(
1214-
obj_any._compliant_frame._with_native(
1215-
native_obj.convert_dtypes(*args, **kwargs)
1216-
)
1217-
)
1218-
if is_pandas_like_series(native_obj):
1219-
return obj_any._with_compliant(
1220-
obj_any._compliant_series._with_native(
1221-
native_obj.convert_dtypes(*args, **kwargs)
1222-
)
1223-
)
1224-
return obj_any
1136+
if not obj.implementation.is_pandas_like():
1137+
return obj
1138+
result = obj._with_compliant(
1139+
obj._compliant._with_native(obj.to_native().convert_dtypes(*args, **kwargs))
1140+
)
1141+
return cast("FrameOrSeriesT", result)
12251142

12261143

12271144
def scale_bytes(sz: int, unit: SizeUnit) -> int | float:

0 commit comments

Comments
 (0)