-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
[Bug] Fix various DatetimeIndex comparison bugs #22074
Conversation
raise TypeError('%s type object %s' % | ||
(type(other), str(other))) | ||
|
||
if is_datetimelike(other): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This previously called self._assert_tzawareness_compat(other)
for other
with timedelta64-dtype
(Really, is_datetimelike
is a footgun)
doc/source/whatsnew/v0.24.0.txt
Outdated
@@ -475,7 +479,7 @@ Numeric | |||
- Bug in :class:`Series` ``__rmatmul__`` doesn't support matrix vector multiplication (:issue:`21530`) | |||
- Bug in :func:`factorize` fails with read-only array (:issue:`12813`) | |||
- Fixed bug in :func:`unique` handled signed zeros inconsistently: for some inputs 0.0 and -0.0 were treated as equal and for some inputs as different. Now they are treated as equal for all inputs (:issue:`21866`) | |||
- | |||
- Bug in :class:`Series` comparison against datetime-like scalars and arrays (:issue:`22074`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not where this line was intended, will move.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it back; this is where it belongs.
with pytest.raises(TypeError): | ||
rng > other | ||
with pytest.raises(TypeError): | ||
rng >= other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything worth checking error message-wise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are pretty scattershot at the moment. I'll give some thought to how that can be addressed.
Codecov Report
@@ Coverage Diff @@
## master #22074 +/- ##
==========================================
- Coverage 92.07% 92.06% -0.01%
==========================================
Files 170 170
Lines 50688 50701 +13
==========================================
+ Hits 46671 46679 +8
- Misses 4017 4022 +5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice fixtures. need to narrow down existing issues which it closes.
@@ -99,31 +100,40 @@ def wrapper(self, other): | |||
meth = getattr(dtl.DatetimeLikeArrayMixin, opname) | |||
|
|||
if isinstance(other, (datetime, np.datetime64, compat.string_types)): | |||
if isinstance(other, datetime): | |||
if isinstance(other, (datetime, np.datetime64)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we do this all over the place, thing about making a type for this (for in internal use only), and/or maybe a is_datetime_scalar
or something, just so we are consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a branch going looking at core.dtypes.common
(inspired by noticing the footgun status if is_datetimelike
), will look at this there so I can get all the places it is used in one swoop.
@@ -152,6 +162,10 @@ class DatetimeArrayMixin(dtl.DatetimeLikeArrayMixin): | |||
'is_year_end', 'is_leap_year'] | |||
_object_ops = ['weekday_name', 'freq', 'tz'] | |||
|
|||
# dummy attribute so that datetime.__eq__(DatetimeArray) defers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh? why don't you just implement and raise NotIMplemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is is a quirk of the stdlib datetime
implementation. datetime == other
will return NotImplemented
instead of raising TypeError
iff other
has a timetuple
attribute.
@@ -275,6 +275,20 @@ def test_comparison_tzawareness_compat(self, op): | |||
with pytest.raises(TypeError): | |||
op(ts, dz) | |||
|
|||
@pytest.mark.parametrize('op', [operator.eq, operator.ne, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty sure we have fixtures for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a fixture for the names ["__eq__", ...]
. This will go on the list of things I'd like to standardize after collecting arithmetic tests in one place.
pls rebase |
AFAICT #7830 is the only issue this closes on its own. BUT after this is done we can make more update That follow-up will be made much less verbose if preceeded by #22068. |
you wnt to merge this first then #22068 ? |
This and #22068 should be orthogonal, either order is fine. |
@@ -496,6 +496,9 @@ Datetimelike | |||
- Fixed bug where two :class:`DateOffset` objects with different ``normalize`` attributes could evaluate as equal (:issue:`21404`) | |||
- Fixed bug where :meth:`Timestamp.resolution` incorrectly returned 1-microsecond ``timedelta`` instead of 1-nanosecond :class:`Timedelta` (:issue:`21336`,:issue:`21365`) | |||
- Bug in :func:`to_datetime` that did not consistently return an :class:`Index` when ``box=True`` was specified (:issue:`21864`) | |||
- Bug in :class:`DatetimeIndex` comparisons where string comparisons incorrectly raises ``TypeError`` (:issue:`22074`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should one be marked #7830 ?
tiny comment, not sure if worth changing |
Let's roll that into one of the cleanup-followups. I'm eager to do the fix-all-the-bugs one that comes after this. |
thxs |
Will have to see which issues this closes. This is also a precursor to upcoming PR that dispatches DataFrame ops to Series (which in turn dispatches to Index).
Fixes #7830 (the OP's example is already fixed, this fixes examples in the comments to that issue)
Fixes DTI half of #19804
git diff upstream/master -u -- "*.py" | flake8 --diff