@@ -92,15 +92,15 @@ def _is_descending(data):
92
92
"""
93
93
Test whether the input data is descending. This is used for auto axis reversal.
94
94
"""
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.
97
97
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
104
104
105
105
106
106
def _to_duck_array (data , strip_units = False ):
@@ -156,7 +156,10 @@ def _to_masked_array(data, *, copy=False):
156
156
units = None
157
157
if ndarray is not Quantity and isinstance (data , Quantity ):
158
158
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 )
160
163
if np .issubdtype (data .dtype , np .integer ):
161
164
data = data .astype (np .float )
162
165
if np .issubdtype (data .dtype , np .number ):
@@ -503,17 +506,25 @@ def _safe_range(data, lo=0, hi=100):
503
506
min_ = max_ = None
504
507
if data .size :
505
508
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 ):
507
510
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 :
509
516
min_ = None
510
517
elif units is not None :
511
518
min_ *= units
512
519
if data .size :
513
520
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 ):
515
522
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 :
517
528
max_ = None
518
529
elif units is not None :
519
530
max_ *= units
0 commit comments