Skip to content

Commit e9841e0

Browse files
authored
refactor: Simplify maybe_convert_dtypes (#3141)
1 parent 76dbde2 commit e9841e0

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

narwhals/_utils.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,21 +1133,12 @@ def maybe_convert_dtypes(
11331133
b boolean
11341134
dtype: object
11351135
"""
1136-
obj_any = cast("Any", obj)
1137-
native_obj = obj_any.to_native()
1138-
if is_pandas_like_dataframe(native_obj):
1139-
return obj_any._with_compliant(
1140-
obj_any._compliant_frame._with_native(
1141-
native_obj.convert_dtypes(*args, **kwargs)
1142-
)
1143-
)
1144-
if is_pandas_like_series(native_obj):
1145-
return obj_any._with_compliant(
1146-
obj_any._compliant_series._with_native(
1147-
native_obj.convert_dtypes(*args, **kwargs)
1148-
)
1149-
)
1150-
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)
11511142

11521143

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

0 commit comments

Comments
 (0)