Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison between TimedeltaIndex/PeriodIndex and 0-dim ndarray raises #26689

Closed
TomAugspurger opened this issue Jun 6, 2019 · 1 comment

Comments

@TomAugspurger
Copy link
Contributor

commented Jun 6, 2019

In [17]: a = pd.timedelta_range('2H', periods=4)

In [18]: a <= np.array(a.to_numpy()[0])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-e196011a0cff> in <module>
----> 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)
<ipython-input-25-e196011a0cff> in <module>
----> 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?

@jbrockmendel

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

will take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.