Skip to content

Commit 322de71

Browse files
author
Jon M. Mease
committed
Support coercing pandas Series into numpy arrays
TODO: add support for datetime arrays in validation and in widget serialization
1 parent 27f6413 commit 322de71

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

plotly/basevalidators.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from copy import deepcopy
99

1010
import numpy as np
11+
import pandas as pd
1112
import re
1213

1314
# Utility functions
@@ -19,6 +20,7 @@ def copy_to_contiguous_readonly_numpy_array(v, dtype=None, force_numeric=False):
1920
# If dtype was not specified then it will be passed to the numpy array constructor as None and the data type
2021
# will be inferred automatically
2122

23+
# TODO: support datetime dtype here and in widget serialization
2224
numeric_kinds = ['u', 'i', 'f']
2325

2426
if not isinstance(v, np.ndarray):
@@ -28,7 +30,7 @@ def copy_to_contiguous_readonly_numpy_array(v, dtype=None, force_numeric=False):
2830
else:
2931
new_v = v.copy()
3032

31-
# Handle force numeric param
33+
# Handle force numeric param
3234
# --------------------------
3335
if force_numeric and new_v.dtype.kind not in numeric_kinds: # (un)signed int, or float
3436
raise ValueError('Input value is not numeric and force_numeric parameter set to True')
@@ -55,7 +57,9 @@ def copy_to_contiguous_readonly_numpy_array(v, dtype=None, force_numeric=False):
5557

5658

5759
def is_array(v):
58-
return isinstance(v, (list, tuple)) or (isinstance(v, np.ndarray) and v.ndim == 1)
60+
return (isinstance(v, (list, tuple)) or
61+
(isinstance(v, np.ndarray) and v.ndim == 1) or
62+
isinstance(v, pd.Series))
5963

6064

6165
def type_str(v):

0 commit comments

Comments
 (0)