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

Warn on ndarray[int] // timedelta #21036

Merged
merged 3 commits into from
May 15, 2018

Conversation

TomAugspurger
Copy link
Contributor

Closes #19761.

In [2]: pd.DatetimeIndex(['1931', '1970', '2017']).view('i8') // pd.Timedelta(1, unit='s')
pandas-dev/bin/ipython:1: FutureWarning: Floor division between integer array and Timedelta is
deprecated. Use 'array // timedelta.value' instead.

Out[2]: array([-1230768000,           0,  1483228800])

Long-term, we'll recommend using to_epoch for the case where people are doing this to do conversion to unix epoch. But #14772 has a few design issues that will take some time to discuss. I think we should just recommend .value for now.

Closes pandas-dev#19761.

```python
In [2]: pd.DatetimeIndex(['1931', '1970', '2017']).view('i8') // pd.Timedelta(1, unit='s')
pandas-dev/bin/ipython:1: FutureWarning: Floor division between integer array and Timedelta is
deprecated. Use 'array // timedelta.value' instead.

Out[2]: array([-1230768000,           0,  1483228800])
```
@TomAugspurger TomAugspurger added this to the 0.23.0 milestone May 14, 2018
@TomAugspurger TomAugspurger added Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type labels May 14, 2018
elif other.dtype.kind == 'i':
# Backwards compatibility
# GH-19761
msg = textwrap.dedent("""\
Copy link
Member

Choose a reason for hiding this comment

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

you don't need the textwrap dedent if you put the string over multiple lines with implicit line continuation and string concatentation?

msg = (" ... "
       " ... ")

(I would personally find that a bit cleaner (also don't need to \), but no big deal)

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've been burned so many times by implicit string concatenation across lines that I try to always avoid it in the hope that it'll be removed in Python 4 :)

@@ -308,7 +308,7 @@ We convert the ``DatetimeIndex`` to an ``int64`` array, then divide by the conve

.. ipython:: python

stamps.view('int64') // pd.Timedelta(1, unit='s')
stamps.view('int64') // pd.Timedelta(1, unit='s').value

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prob change this example to

In [11]: i
Out[11]: DatetimeIndex(['1931-01-01', '1970-01-01', '2017-01-01'], dtype='datetime64[ns]', freq=None)

In [12]: (i-pd.Timestamp(0)) // pd.Timedelta(1, unit='s')
Out[12]: Int64Index([-1230768000, 0, 1483228800], dtype='int64')

Copy link
Contributor Author

@TomAugspurger TomAugspurger May 15, 2018

Choose a reason for hiding this comment

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

That makes sense for now (till to_epoch is ready).

@jreback jreback added the Deprecate Functionality to remove in pandas label May 14, 2018
@codecov
Copy link

codecov bot commented May 14, 2018

Codecov Report

Merging #21036 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #21036   +/-   ##
=======================================
  Coverage   91.82%   91.82%           
=======================================
  Files         153      153           
  Lines       49502    49502           
=======================================
  Hits        45457    45457           
  Misses       4045     4045
Flag Coverage Δ
#multiple 90.22% <ø> (ø) ⬆️
#single 41.88% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/io/parsers.py 95.46% <0%> (ø) ⬆️

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 a5c02d5...9fa7583. Read the comment docs.

@jreback jreback merged commit 1a9937d into pandas-dev:master May 15, 2018
@jreback
Copy link
Contributor

jreback commented May 15, 2018

thanks!

# GH-19761
msg = textwrap.dedent("""\
Floor division between integer array and Timedelta is
deprecated. Use 'array // timedelta.value' instead.
Copy link
Member

Choose a reason for hiding this comment

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

Since you updated the example in the docs, maybe we should reflect this as well in the deprecation message?

@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented May 15, 2018 via email

@jorisvandenbossche
Copy link
Member

I don't know who else would be doing that :-) But it's true that it's not necessarily the case. I can do a PR to add that explanation in addition to the current one if you like.

@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented May 15, 2018 via email

@germannp
Copy link

germannp commented Dec 5, 2019

Should users also get warned on timedelta // int, which happens with timedelta % int too? Maybe the warning should pop up everytime a number is implicitly converted to a timestamp, as the current behavior does not seem very consistent with addition for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Numeric Operations Arithmetic, Comparison, and Logical operations Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: regression in Timedelta.__rfloordiv__ with integer data
4 participants