Skip to content

Commit 54acfb1

Browse files
committed
Support object-type coordinate inputs (fix #320)
1 parent f9ac77f commit 54acfb1

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

proplot/internals/inputs.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ def _is_descending(data):
9292
"""
9393
Test whether the input data is descending. This is used for auto axis reversal.
9494
"""
95-
# NOTE: Want this to work with e.g. datetime axes but fail for strange
96-
# mixed types so filter against object dtypes rather than using _is_numeric
95+
# NOTE: Want this to work with e.g. datetime object arrays and numpy datetime
96+
# arrays so use try except clause.
9797
data = _to_numpy_array(data)
98-
return (
99-
data.ndim == 1
100-
and data.size > 1
101-
and data.dtype != 'O'
102-
and np.all(np.sign(np.diff(data)) == -1)
103-
)
98+
if data.ndim > 1 or data.size < 2:
99+
return False
100+
try:
101+
return all(x != abs(x) for x in np.diff(data))
102+
except TypeError:
103+
return False
104104

105105

106106
def _to_duck_array(data, strip_units=False):
@@ -156,7 +156,10 @@ def _to_masked_array(data, *, copy=False):
156156
units = None
157157
if ndarray is not Quantity and isinstance(data, Quantity):
158158
data, units = data.magnitude, data.units
159-
data = ma.masked_invalid(data, copy=copy)
159+
if data.dtype == 'O':
160+
data = ma.array(data, mask=False)
161+
else:
162+
data = ma.masked_invalid(data, copy=copy)
160163
if np.issubdtype(data.dtype, np.integer):
161164
data = data.astype(np.float)
162165
if np.issubdtype(data.dtype, np.number):
@@ -503,17 +506,25 @@ def _safe_range(data, lo=0, hi=100):
503506
min_ = max_ = None
504507
if data.size:
505508
min_ = np.min(data) if lo <= 0 else np.percentile(data, lo)
506-
if np.issubdtype(min_.dtype, np.integer):
509+
if hasattr(min_, 'dtype') and np.issubdtype(min_.dtype, np.integer):
507510
min_ = np.float(min_)
508-
if not np.isfinite(min_):
511+
try:
512+
is_finite = np.isfinite(min_)
513+
except TypeError:
514+
is_finite = True
515+
if not is_finite:
509516
min_ = None
510517
elif units is not None:
511518
min_ *= units
512519
if data.size:
513520
max_ = np.max(data) if hi >= 100 else np.percentile(data, hi)
514-
if np.issubdtype(max_.dtype, np.integer):
521+
if hasattr(max_, 'dtype') and np.issubdtype(max_.dtype, np.integer):
515522
max_ = np.float(max_)
516-
if not np.isfinite(max_):
523+
try:
524+
is_finite = np.isfinite(min_)
525+
except TypeError:
526+
is_finite = True
527+
if not is_finite:
517528
max_ = None
518529
elif units is not None:
519530
max_ *= units

0 commit comments

Comments
 (0)