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

Timedelta returns wrong value #27285

Closed
ayang opened this issue Jul 8, 2019 · 8 comments
Closed

Timedelta returns wrong value #27285

ayang opened this issue Jul 8, 2019 · 8 comments
Labels
Bug Timedelta Timedelta data type

Comments

@ayang
Copy link

ayang commented Jul 8, 2019

Code Sample

In [6]: pd.Timedelta(6, 'M')
Out[6]: Timedelta('182 days 14:54:36')

In [7]: pd.Timedelta('6M')
Out[7]: Timedelta('0 days 00:06:00')

In [8]: pd.Timedelta(6, 'W')
Out[8]: Timedelta('42 days 00:00:00')

In [9]: pd.Timedelta('6W')
Out[9]: Timedelta('42 days 00:00:00')

Problem description

Out[7] shoud return 182 days but 6 minutes

@jreback
Copy link
Contributor

jreback commented Jul 8, 2019

In [1]: pd.__version__                                                                                                                                                                                                                                   
Out[1]: '0.25.0.dev0+889.g903a09c6a'

In [2]: pd.Timedelta('6M')                                                                                                                                                                                                                               
Out[2]: Timedelta('0 days 00:06:00')

In [3]: pd.Timedelta('6min')                                                                                                                                                                                                                             
Out[3]: Timedelta('0 days 00:06:00')

In [4]: pd.Timedelta(6, 'min')                                                                                                                                                                                                                           
Out[4]: Timedelta('0 days 00:06:00')

In [5]: pd.Timedelta(6, 'M')                                                                                                                                                                                                                             
/nas/local/simscripts/jreback/.nest/bamboo/bin/ipython:1: FutureWarning: M and Y units are deprecated and will be removed in a future version.
  #!/usr/bin/python2.7
Out[5]: Timedelta('182 days 14:54:36')

M was deprecated, you should use min for minutes; in any event months are generally not really useful / supported with Timedelta as they don't represent a fixed period.

@jreback jreback closed this as completed Jul 8, 2019
@jreback jreback added Timedelta Timedelta data type Usage Question labels Jul 8, 2019
@jreback jreback added this to the No action milestone Jul 8, 2019
@jorisvandenbossche
Copy link
Member

Given that 'M' is the unit for month, and also when specifying a freq in other situations it is interpreted like that, should we maybe not interpret '6M' as 6 minutes?

@jbrockmendel
Copy link
Member

For strptime and strftime %M is minutes, e.g. %y-%m-%d %H:%M:%S

@jorisvandenbossche
Copy link
Member

For strptime and strftime %M is minutes

Ah, that's true. But I would argue that units and offsets are "closer" to timedelta, so are more important to take into account when deciding what "M" should mean (but it is certainly unfortunate that formats strings and units are basically the other way around)

@jbrockmendel
Copy link
Member

we now no longer allow passing unit="M" but we do allow pd.Timedelta("6M") to mean 6 minutes. Do we want to disallow it there too?

@theNicelander
Copy link

If I'm reading this correctly, the plan is to drop support for Monthly Timedeltas in the future. There are many cases where monthly Timedeltas are very useful, even if they don't represent a fixed amount of time as @jreback mentioned. Most businesses rely on monthly reporting, so having the option to do monthly Timedeltas is crucial.

@jreback
Copy link
Contributor

jreback commented Dec 16, 2019

@theNicelander you can already do monthly timeseltas with offsets which handle this type of. variable movement

Timedelta is a fixed unit and so doesn’t support non fixed values

@mroeschke
Copy link
Member

Looks like we've deprecated M so I don't think this issue is actionable anymore. Closing

In [16]: pd.Timedelta("6M")
FutureWarning: Units 'M', 'Y' and 'y' do not represent unambiguous timedelta values and will be removed in a future version
Out[16]: Timedelta('0 days 00:06:00')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

6 participants