@@ -98,6 +98,11 @@ def is_pandas_series(ser: Any) -> TypeGuard[pd.Series[Any]]:
98
98
return (pd := get_pandas ()) is not None and isinstance (ser , pd .Series )
99
99
100
100
101
+ def is_pandas_index (index : Any ) -> TypeGuard [pd .Index ]:
102
+ """Check whether `index` is a pandas Index without importing pandas."""
103
+ return (pd := get_pandas ()) is not None and isinstance (index , pd .Index )
104
+
105
+
101
106
def is_modin_dataframe (df : Any ) -> TypeGuard [mpd .DataFrame ]:
102
107
"""Check whether `df` is a modin DataFrame without importing modin."""
103
108
return (mpd := get_modin ()) is not None and isinstance (df , mpd .DataFrame )
@@ -108,6 +113,13 @@ def is_modin_series(ser: Any) -> TypeGuard[mpd.Series]:
108
113
return (mpd := get_modin ()) is not None and isinstance (ser , mpd .Series )
109
114
110
115
116
+ def is_modin_index (index : Any ) -> TypeGuard [mpd .Index ]:
117
+ """Check whether `index` is a modin Index without importing modin."""
118
+ return (mpd := get_modin ()) is not None and isinstance (
119
+ index , mpd .Index
120
+ ) # pragma: no cover
121
+
122
+
111
123
def is_cudf_dataframe (df : Any ) -> TypeGuard [cudf .DataFrame ]:
112
124
"""Check whether `df` is a cudf DataFrame without importing cudf."""
113
125
return (cudf := get_cudf ()) is not None and isinstance (df , cudf .DataFrame )
@@ -118,6 +130,13 @@ def is_cudf_series(ser: Any) -> TypeGuard[cudf.Series[Any]]:
118
130
return (cudf := get_cudf ()) is not None and isinstance (ser , cudf .Series )
119
131
120
132
133
+ def is_cudf_index (index : Any ) -> TypeGuard [cudf .Index ]:
134
+ """Check whether `index` is a cudf Index without importing cudf."""
135
+ return (cudf := get_cudf ()) is not None and isinstance (
136
+ index , cudf .Index
137
+ ) # pragma: no cover
138
+
139
+
121
140
def is_dask_dataframe (df : Any ) -> TypeGuard [dd .DataFrame ]:
122
141
"""Check whether `df` is a Dask DataFrame without importing Dask."""
123
142
return (dd := get_dask_dataframe ()) is not None and isinstance (df , dd .DataFrame )
@@ -174,13 +193,24 @@ def is_pandas_like_dataframe(df: Any) -> bool:
174
193
return is_pandas_dataframe (df ) or is_modin_dataframe (df ) or is_cudf_dataframe (df )
175
194
176
195
177
- def is_pandas_like_series (arr : Any ) -> bool :
196
+ def is_pandas_like_series (ser : Any ) -> bool :
178
197
"""
179
- Check whether `arr ` is a pandas-like Series without doing any imports
198
+ Check whether `ser ` is a pandas-like Series without doing any imports
180
199
181
200
By "pandas-like", we mean: pandas, Modin, cuDF.
182
201
"""
183
- return is_pandas_series (arr ) or is_modin_series (arr ) or is_cudf_series (arr )
202
+ return is_pandas_series (ser ) or is_modin_series (ser ) or is_cudf_series (ser )
203
+
204
+
205
+ def is_pandas_like_index (index : Any ) -> bool :
206
+ """
207
+ Check whether `index` is a pandas-like Index without doing any imports
208
+
209
+ By "pandas-like", we mean: pandas, Modin, cuDF.
210
+ """
211
+ return (
212
+ is_pandas_index (index ) or is_modin_index (index ) or is_cudf_index (index )
213
+ ) # pragma: no cover
184
214
185
215
186
216
def is_into_series (native_series : IntoSeries ) -> bool :
0 commit comments