Skip to content

Commit fef6dbe

Browse files
committed
modin and cudf
1 parent 9a9283a commit fef6dbe

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

packages/python/plotly/plotly/data/__init__.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import narwhals.stable.v1 as nw
88

9-
AVAILABLE_BACKENDS = {"pandas", "polars", "pyarrow"}
9+
AVAILABLE_BACKENDS = {"pandas", "polars", "pyarrow", "modin", "cudf"}
10+
BACKENDS_WITH_INDEX_SUPPORT = {"pandas", "modin", "cudf"}
1011

1112

1213
def gapminder(
@@ -35,7 +36,7 @@ def gapminder(
3536
pretty_names: bool
3637
If True, prettifies the column names
3738
38-
return_type: {'pandas', 'polars', 'pyarrow'}
39+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
3940
Type of the resulting dataframe
4041
4142
Returns
@@ -93,7 +94,7 @@ def tips(pretty_names=False, return_type="pandas"):
9394
pretty_names: bool
9495
If True, prettifies the column names
9596
96-
return_type: {'pandas', 'polars', 'pyarrow'}
97+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
9798
Type of the resulting dataframe
9899
99100
Returns
@@ -127,7 +128,7 @@ def iris(return_type="pandas"):
127128
128129
Parameters
129130
----------
130-
return_type: {'pandas', 'polars', 'pyarrow'}
131+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
131132
Type of the resulting dataframe
132133
133134
Returns
@@ -145,7 +146,7 @@ def wind(return_type="pandas"):
145146
146147
Parameters
147148
----------
148-
return_type: {'pandas', 'polars', 'pyarrow'}
149+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
149150
Type of the resulting dataframe
150151
151152
Returns
@@ -164,7 +165,7 @@ def election(return_type="pandas"):
164165
165166
Parameters
166167
----------
167-
return_type: {'pandas', 'polars', 'pyarrow'}
168+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
168169
Type of the resulting dataframe
169170
170171
Returns
@@ -208,7 +209,7 @@ def carshare(return_type="pandas"):
208209
209210
Parameters
210211
----------
211-
return_type: {'pandas', 'polars', 'pyarrow'}
212+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
212213
Type of the resulting dataframe
213214
214215
Returns
@@ -233,7 +234,7 @@ def stocks(indexed=False, datetimes=False, return_type="pandas"):
233234
datetimes: bool
234235
Whether or not the 'date' column will be of datetime type
235236
236-
return_type: {'pandas', 'polars', 'pyarrow'}
237+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
237238
Type of the resulting dataframe
238239
239240
Returns
@@ -245,8 +246,8 @@ def stocks(indexed=False, datetimes=False, return_type="pandas"):
245246
is named 'company'
246247
If `datetimes` is True, the 'date' column will be a datetime column
247248
"""
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"
250251
raise NotImplementedError(msg)
251252

252253
df = nw.from_native(
@@ -274,7 +275,7 @@ def experiment(indexed=False, return_type="pandas"):
274275
If True, then the index is named "participant".
275276
Applicable only if `return_type='pandas'`
276277
277-
return_type: {'pandas', 'polars', 'pyarrow'}
278+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
278279
Type of the resulting dataframe
279280
280281
Returns
@@ -285,8 +286,8 @@ def experiment(indexed=False, return_type="pandas"):
285286
If `indexed` is True, the data frame index is named "participant"
286287
"""
287288

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"
290291
raise NotImplementedError(msg)
291292

292293
df = nw.from_native(
@@ -310,7 +311,7 @@ def medals_wide(indexed=False, return_type="pandas"):
310311
Whether or not the 'nation' column is used as the index and the column index
311312
is named 'medal'. Applicable only if `return_type='pandas'`
312313
313-
return_type: {'pandas', 'polars', 'pyarrow'}
314+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
314315
Type of the resulting dataframe
315316
316317
Returns
@@ -322,8 +323,8 @@ def medals_wide(indexed=False, return_type="pandas"):
322323
is named 'medal'
323324
"""
324325

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"
327328
raise NotImplementedError(msg)
328329

329330
df = nw.from_native(
@@ -347,7 +348,7 @@ def medals_long(indexed=False, return_type="pandas"):
347348
Whether or not the 'nation' column is used as the index.
348349
Applicable only if `return_type='pandas'`
349350
350-
return_type: {'pandas', 'polars', 'pyarrow'}
351+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
351352
Type of the resulting dataframe
352353
353354
Returns
@@ -357,8 +358,8 @@ def medals_long(indexed=False, return_type="pandas"):
357358
If `indexed` is True, the 'nation' column is used as the index.
358359
"""
359360

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"
362363
raise NotImplementedError(msg)
363364

364365
df = nw.from_native(
@@ -387,7 +388,7 @@ def _get_dataset(d, return_type):
387388
d: str
388389
Name of the dataset to load.
389390
390-
return_type: {'pandas', 'polars', 'pyarrow'}
391+
return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'}
391392
Type of the resulting dataframe
392393
393394
Returns
@@ -406,7 +407,12 @@ def _get_dataset(d, return_type):
406407
raise NotImplementedError(msg)
407408

408409
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
410416
backend = import_module(module_to_load)
411417
except ModuleNotFoundError:
412418
msg = f"return_type={return_type}, but {return_type} is not installed"

0 commit comments

Comments
 (0)