6
6
7
7
import narwhals .stable .v1 as nw
8
8
9
- AVAILABLE_BACKENDS = {"pandas" , "polars" , "pyarrow" }
9
+ AVAILABLE_BACKENDS = {"pandas" , "polars" , "pyarrow" , "modin" , "cudf" }
10
+ BACKENDS_WITH_INDEX_SUPPORT = {"pandas" , "modin" , "cudf" }
10
11
11
12
12
13
def gapminder (
@@ -35,7 +36,7 @@ def gapminder(
35
36
pretty_names: bool
36
37
If True, prettifies the column names
37
38
38
- return_type: {'pandas', 'polars', 'pyarrow'}
39
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
39
40
Type of the resulting dataframe
40
41
41
42
Returns
@@ -93,7 +94,7 @@ def tips(pretty_names=False, return_type="pandas"):
93
94
pretty_names: bool
94
95
If True, prettifies the column names
95
96
96
- return_type: {'pandas', 'polars', 'pyarrow'}
97
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
97
98
Type of the resulting dataframe
98
99
99
100
Returns
@@ -127,7 +128,7 @@ def iris(return_type="pandas"):
127
128
128
129
Parameters
129
130
----------
130
- return_type: {'pandas', 'polars', 'pyarrow'}
131
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
131
132
Type of the resulting dataframe
132
133
133
134
Returns
@@ -145,7 +146,7 @@ def wind(return_type="pandas"):
145
146
146
147
Parameters
147
148
----------
148
- return_type: {'pandas', 'polars', 'pyarrow'}
149
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
149
150
Type of the resulting dataframe
150
151
151
152
Returns
@@ -164,7 +165,7 @@ def election(return_type="pandas"):
164
165
165
166
Parameters
166
167
----------
167
- return_type: {'pandas', 'polars', 'pyarrow'}
168
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
168
169
Type of the resulting dataframe
169
170
170
171
Returns
@@ -208,7 +209,7 @@ def carshare(return_type="pandas"):
208
209
209
210
Parameters
210
211
----------
211
- return_type: {'pandas', 'polars', 'pyarrow'}
212
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
212
213
Type of the resulting dataframe
213
214
214
215
Returns
@@ -233,7 +234,7 @@ def stocks(indexed=False, datetimes=False, return_type="pandas"):
233
234
datetimes: bool
234
235
Whether or not the 'date' column will be of datetime type
235
236
236
- return_type: {'pandas', 'polars', 'pyarrow'}
237
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
237
238
Type of the resulting dataframe
238
239
239
240
Returns
@@ -245,8 +246,8 @@ def stocks(indexed=False, datetimes=False, return_type="pandas"):
245
246
is named 'company'
246
247
If `datetimes` is True, the 'date' column will be a datetime column
247
248
"""
248
- if indexed and return_type != "pandas" :
249
- msg = "Cannot set index for backend different from pandas "
249
+ if indexed and return_type not in BACKENDS_WITH_INDEX_SUPPORT :
250
+ msg = f"Backend ' { return_type } ' does not support setting index "
250
251
raise NotImplementedError (msg )
251
252
252
253
df = nw .from_native (
@@ -274,7 +275,7 @@ def experiment(indexed=False, return_type="pandas"):
274
275
If True, then the index is named "participant".
275
276
Applicable only if `return_type='pandas'`
276
277
277
- return_type: {'pandas', 'polars', 'pyarrow'}
278
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
278
279
Type of the resulting dataframe
279
280
280
281
Returns
@@ -285,8 +286,8 @@ def experiment(indexed=False, return_type="pandas"):
285
286
If `indexed` is True, the data frame index is named "participant"
286
287
"""
287
288
288
- if indexed and return_type != "pandas" :
289
- msg = "Cannot set index for backend different from pandas "
289
+ if indexed and return_type not in BACKENDS_WITH_INDEX_SUPPORT :
290
+ msg = f"Backend ' { return_type } ' does not support setting index "
290
291
raise NotImplementedError (msg )
291
292
292
293
df = nw .from_native (
@@ -310,7 +311,7 @@ def medals_wide(indexed=False, return_type="pandas"):
310
311
Whether or not the 'nation' column is used as the index and the column index
311
312
is named 'medal'. Applicable only if `return_type='pandas'`
312
313
313
- return_type: {'pandas', 'polars', 'pyarrow'}
314
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
314
315
Type of the resulting dataframe
315
316
316
317
Returns
@@ -322,8 +323,8 @@ def medals_wide(indexed=False, return_type="pandas"):
322
323
is named 'medal'
323
324
"""
324
325
325
- if indexed and return_type != "pandas" :
326
- msg = "Cannot set index for backend different from pandas "
326
+ if indexed and return_type not in BACKENDS_WITH_INDEX_SUPPORT :
327
+ msg = f"Backend ' { return_type } ' does not support setting index "
327
328
raise NotImplementedError (msg )
328
329
329
330
df = nw .from_native (
@@ -347,7 +348,7 @@ def medals_long(indexed=False, return_type="pandas"):
347
348
Whether or not the 'nation' column is used as the index.
348
349
Applicable only if `return_type='pandas'`
349
350
350
- return_type: {'pandas', 'polars', 'pyarrow'}
351
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
351
352
Type of the resulting dataframe
352
353
353
354
Returns
@@ -357,8 +358,8 @@ def medals_long(indexed=False, return_type="pandas"):
357
358
If `indexed` is True, the 'nation' column is used as the index.
358
359
"""
359
360
360
- if indexed and return_type != "pandas" :
361
- msg = "Cannot set index for backend different from pandas "
361
+ if indexed and return_type not in BACKENDS_WITH_INDEX_SUPPORT :
362
+ msg = f"Backend ' { return_type } ' does not support setting index "
362
363
raise NotImplementedError (msg )
363
364
364
365
df = nw .from_native (
@@ -387,7 +388,7 @@ def _get_dataset(d, return_type):
387
388
d: str
388
389
Name of the dataset to load.
389
390
390
- return_type: {'pandas', 'polars', 'pyarrow'}
391
+ return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf' }
391
392
Type of the resulting dataframe
392
393
393
394
Returns
@@ -406,7 +407,12 @@ def _get_dataset(d, return_type):
406
407
raise NotImplementedError (msg )
407
408
408
409
try :
409
- module_to_load = "pyarrow.csv" if return_type == "pyarrow" else return_type
410
+ if return_type == "pyarrow" :
411
+ module_to_load = "pyarrow.csv"
412
+ elif return_type == "modin" :
413
+ module_to_load = "modin.pandas"
414
+ else :
415
+ module_to_load = return_type
410
416
backend = import_module (module_to_load )
411
417
except ModuleNotFoundError :
412
418
msg = f"return_type={ return_type } , but { return_type } is not installed"
0 commit comments