From f5314ccda2701847961524650321f92ad76bce45 Mon Sep 17 00:00:00 2001 From: Dan Redding <125183946+dangotbanned@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:22:37 +0000 Subject: [PATCH] fix(typing): resolve remaining `utils.py` warnings (#1968) Adds `_is_range_index` to fix 6 warnings --- narwhals/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/narwhals/utils.py b/narwhals/utils.py index a4606eedb..33aefc16d 100644 --- a/narwhals/utils.py +++ b/narwhals/utils.py @@ -766,12 +766,16 @@ def maybe_reset_index(obj: FrameOrSeriesT) -> FrameOrSeriesT: return obj_any # type: ignore[no-any-return] +def _is_range_index(obj: Any, native_namespace: Any) -> TypeIs[pd.RangeIndex]: + return isinstance(obj, native_namespace.RangeIndex) + + def _has_default_index( native_frame_or_series: pd.Series | pd.DataFrame, native_namespace: Any ) -> bool: index = native_frame_or_series.index return ( - isinstance(index, native_namespace.RangeIndex) + _is_range_index(index, native_namespace) and index.start == 0 and index.stop == len(index) and index.step == 1