Skip to content

BUG: Week ('W') does not work as suffixes for a string passed to Timedelta. #12691

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

Open
belteshassar opened this issue Mar 22, 2016 · 4 comments
Labels
Bug Timedelta Timedelta data type

Comments

@belteshassar
Copy link

I initially posted this on #12136, as I intended to fix it with the same patch, but I think it deserves its own issue as my initial idea for a fix may in fact change the behaviour for strings suffixed by capital M. Previously, those would be interpreted as minutes because of the unit.lower() in https://github.com/pydata/pandas/blob/master/pandas/tslib.pyx#L2820

Apparently, timedelta_from_spec() doesn't recognize all the abbreviations that are allowed in the unit parameter. Consider for example:

>>> pd.Timedelta('1Y')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas\tslib.pyx", line 2373, in pandas.tslib.Timedelta.__new__ (pandas\tslib.c:43241)
    value = np.timedelta64(parse_timedelta_string(value, unit, False))
  File "pandas\tslib.pyx", line 3010, in pandas.tslib.parse_timedelta_string (pandas\tslib.c:52603)
    raise
  File "pandas\tslib.pyx", line 3005, in pandas.tslib.parse_timedelta_string (pandas\tslib.c:52506)
    r = timedelta_from_spec(number, frac, unit)
  File "pandas\tslib.pyx", line 2822, in pandas.tslib.timedelta_from_spec (pandas\tslib.c:50601)
    raise ValueError("invalid abbreviation: {0}".format(unit))
ValueError: invalid abbreviation: Y

while

>>> pd.Timedelta(1, unit='Y')
Timedelta('365 days 05:49:12')

Same goes for Week.

Month is slightly trickier. As noted above, we have this inconsistency that we might want to do something about:

>>> pd.Timedelta('1M')
Timedelta('0 days 00:01:00')
>>> pd.Timedelta(1, unit='M')
Timedelta('30 days 10:29:06')
@jreback
Copy link
Contributor

jreback commented Mar 22, 2016

note that T is the pandas indicator for minutes (to avoid this kind of ambiguity).

@jreback jreback added this to the 0.18.1 milestone Mar 22, 2016
@jreback jreback modified the milestones: 0.18.2, 0.18.1 Apr 26, 2016
@jorisvandenbossche
Copy link
Member

Given that we think of deprecating those units (see #14024), I think this can be closed (no need to fix this)

@jorisvandenbossche jorisvandenbossche removed this from the 0.19.0 milestone Aug 19, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: No action, Next Major Release May 12, 2017
@jorisvandenbossche jorisvandenbossche changed the title Week, month and year do not work as suffixes for a string passed to Timedelta. BUG: Wee ('W') does not work as suffixes for a string passed to Timedelta. May 12, 2017
@jorisvandenbossche
Copy link
Member

Since we will fully deprecate/remove 'Y' and 'M' (for month) as allowed units, renamed this issue for the remaining issue with 'W' (this can be allowed).

@jorisvandenbossche jorisvandenbossche changed the title BUG: Wee ('W') does not work as suffixes for a string passed to Timedelta. BUG: Week ('W') does not work as suffixes for a string passed to Timedelta. May 12, 2017
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@jbrockmendel
Copy link
Member

note that T is the pandas indicator for minutes (to avoid this kind of ambiguity).

@jreback ive been looking at this for unrelated reasons: where do these come from? (T for minutes, L for milli, ...)

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

5 participants