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

Revert change to comparison op with datetime.date objects #21361

Merged

Conversation

TomAugspurger
Copy link
Contributor

cc @jbrockmendel, @innominate227

FYI, @jorisvandenbossche the whatsnew will conflict with your other PR

@TomAugspurger TomAugspurger added Datetime Datetime data dtype Numeric Operations Arithmetic, Comparison, and Logical operations labels Jun 7, 2018
@TomAugspurger TomAugspurger added this to the 0.23.1 milestone Jun 7, 2018
@codecov
Copy link

codecov bot commented Jun 7, 2018

Codecov Report

Merging #21361 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21361      +/-   ##
==========================================
+ Coverage   91.89%   91.89%   +<.01%     
==========================================
  Files         153      153              
  Lines       49579    49590      +11     
==========================================
+ Hits        45559    45570      +11     
  Misses       4020     4020
Flag Coverage Δ
#multiple 90.29% <100%> (ø) ⬆️
#single 41.85% <36.36%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/ops.py 96.41% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f6ea67...174c458. Read the comment docs.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, otherwise looks good

@@ -1197,8 +1200,35 @@ def wrapper(self, other, axis=None):
if is_datetime64_dtype(self) or is_datetime64tz_dtype(self):
# Dispatch to DatetimeIndex to ensure identical
# Series/Index behavior
if (isinstance(other, datetime.date) and
not isinstance(other, datetime.datetime)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this check needed? (I would not expect it ever to be true if it is a datetime.date ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently datetime.datetime subclasses datetime.date

https://bugs.python.org/issue28878

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than inlineing this, I think would be better to move to a module level function, maybe
other = maybe_coerce_other(other, op)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean just the new bit I added, right?

I'm inclined to leave it here since we'll just be deleting it soon (is 0.24.0 too soon?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently datetime.datetime subclasses datetime.date

Ah, only checked the other way around :-)

Yeah, if this is only temporary code I would just leave it here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, is there an issue to fix this for 0.24.0? (can you add a TODO mention here)


.. code-block:: python

>>> pd.Series(pd.date_range('2017', periods=2)) > datetime.date(2017, 1, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this example is still needed? (it's kind of repetition of above? and the note is already quite long)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I agree this is too much, the first part is great!

@@ -10,12 +10,70 @@ and bug fixes. We recommend that all users upgrade to this version.
:local:
:backlinks: none

.. _whatsnew_0231.enhancements:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left-over from rebase


.. _whatsnew_0231.fixed_regressions:

Fixed Regressions
~~~~~~~~~~~~~~~~~

**Comparing Series with datetime.date**

We've reverted a 0.23.0 change to comparing a :class:`Series` holding datetimes and a ``datetime.date`` object (:issue:`21152`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use date=datetime64[ns]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh was just saying that users talk about dtypes, rather than Series holding datetimes. no big deal really.

**Comparing Series with datetime.date**

We've reverted a 0.23.0 change to comparing a :class:`Series` holding datetimes and a ``datetime.date`` object (:issue:`21152`).
In pandas 0.22 and earlier, comparing a Series holding datetimes and ``datetime.date`` objects would coerce the ``datetime.date`` to a datetime before comapring.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use double back ticks around Series (or :class`Series`


We've reverted a 0.23.0 change to comparing a :class:`Series` holding datetimes and a ``datetime.date`` object (:issue:`21152`).
In pandas 0.22 and earlier, comparing a Series holding datetimes and ``datetime.date`` objects would coerce the ``datetime.date`` to a datetime before comapring.
This was inconsistent with Python, NumPy, and :class:`DatetimeIndex`, which never consider a datetime and ``datetime.date`` equal.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should double backtick on Python, NumPy

In pandas 0.22 and earlier, comparing a Series holding datetimes and ``datetime.date`` objects would coerce the ``datetime.date`` to a datetime before comapring.
This was inconsistent with Python, NumPy, and :class:`DatetimeIndex`, which never consider a datetime and ``datetime.date`` equal.

In 0.23.0, we unified operations between DatetimeIndex and Series, and in the process changed comparisons between a Series of datetimes and ``datetime.date`` without warning.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double backticks on DTI & Series


.. code-block:: python

>>> pd.Series(pd.date_range('2017', periods=2)) > datetime.date(2017, 1, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I agree this is too much, the first part is great!

@@ -1197,8 +1200,35 @@ def wrapper(self, other, axis=None):
if is_datetime64_dtype(self) or is_datetime64tz_dtype(self):
# Dispatch to DatetimeIndex to ensure identical
# Series/Index behavior
if (isinstance(other, datetime.date) and
not isinstance(other, datetime.datetime)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than inlineing this, I think would be better to move to a module level function, maybe
other = maybe_coerce_other(other, op)

@jorisvandenbossche jorisvandenbossche changed the title Revert change to comarpison op Revert change to comparison op with datetime.date objects Jun 8, 2018
@jorisvandenbossche
Copy link
Member

@TomAugspurger This is ready?

@TomAugspurger
Copy link
Contributor Author

IMO, yes. I didn't change the quoting in the docs, since #19750 hasn't been resolved (just replied there).

@jorisvandenbossche jorisvandenbossche merged commit d79203a into pandas-dev:master Jun 8, 2018
@TomAugspurger TomAugspurger deleted the datetime-date-compare branch June 12, 2018 14:29
TomAugspurger added a commit to TomAugspurger/pandas that referenced this pull request Jun 12, 2018
TomAugspurger added a commit that referenced this pull request Jun 12, 2018
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

datetime.date no longer coerced to datetime64 for comparison operations
3 participants