Comparison between TimedeltaIndex/PeriodIndex and 0-dim ndarray raises (original) (raw)
In [17]: a = pd.timedelta_range('2H', periods=4)
In [18]: a <= np.array(a.to_numpy()[0])
TypeError Traceback (most recent call last) in ----> 1 a <= np.array(a.to_numpy()[0])
~/sandbox/pandas/pandas/core/indexes/datetimelike.py in wrapper(self, other) 116 other = other._values 117 --> 118 result = op(self._data, maybe_unwrap_index(other)) 119 return result 120
~/sandbox/pandas/pandas/core/arrays/timedeltas.py in wrapper(self, other) 78 79 elif not is_list_like(other): ---> 80 return ops.invalid_comparison(self, other, op) 81 82 elif len(other) != len(self):
~/sandbox/pandas/pandas/core/ops.py in invalid_comparison(left, right, op) 1196 else: 1197 raise TypeError("Invalid comparison between dtype={dtype} and {typ}" -> 1198 .format(dtype=left.dtype, typ=type(right).name)) 1199 return res_values 1200
TypeError: Invalid comparison between dtype=timedelta64[ns] and ndarray
Works for DatetimeIndex.
Raises a different error for PeriodIndex
In [24]: a = pd.period_range('2000', periods=4)
In [25]: a <= np.array(a.to_numpy()[0])
TypeError Traceback (most recent call last) in ----> 1 a <= np.array(a.to_numpy()[0])
~/sandbox/pandas/pandas/core/indexes/datetimelike.py in wrapper(self, other) 116 other = other._values 117 --> 118 result = op(self._data, maybe_unwrap_index(other)) 119 return result 120
~/sandbox/pandas/pandas/core/arrays/period.py in wrapper(self, other) 76 result.fill(nat_result) 77 else: ---> 78 other = Period(other, freq=self.freq) 79 result = op(other.ordinal) 80
~/sandbox/pandas/pandas/_libs/tslibs/period.pyx in pandas._libs.tslibs.period.Period.new() 2448 ordinal = converted.ordinal 2449 -> 2450 elif is_null_datetimelike(value) or value in nat_strings: 2451 ordinal = NPY_NAT 2452
TypeError: unhashable type: 'numpy.ndarray'
@jbrockmendel would you be interested in looking at this?