Skip to content

Commit 30ff0b8

Browse files
authored
chore: use set_axis in maybe_set_index (#1598)
1 parent 07f3d0e commit 30ff0b8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

narwhals/utils.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -548,18 +548,18 @@ def maybe_set_index(
548548
df_any._compliant_frame._from_native_frame(native_obj.set_index(keys))
549549
)
550550
elif is_pandas_like_series(native_obj):
551+
from narwhals._pandas_like.utils import set_axis
552+
551553
if column_names:
552554
msg = "Cannot set index using column names on a Series"
553555
raise ValueError(msg)
554556

555-
if (
556-
df_any._compliant_series._implementation is Implementation.PANDAS
557-
and df_any._compliant_series._backend_version < (1,)
558-
): # pragma: no cover
559-
native_obj = native_obj.set_axis(keys, inplace=False)
560-
else:
561-
native_obj = native_obj.set_axis(keys)
562-
557+
native_obj = set_axis(
558+
native_obj,
559+
keys,
560+
implementation=obj._compliant_series._implementation, # type: ignore[union-attr]
561+
backend_version=obj._compliant_series._backend_version, # type: ignore[union-attr]
562+
)
563563
return df_any._from_compliant_series( # type: ignore[no-any-return]
564564
df_any._compliant_series._from_native_series(native_obj)
565565
)

0 commit comments

Comments
 (0)