-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: the pd.to_timedelta() incorrectly parses the 'M' as minutes. #34968
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
Comments
From timedeltas.pyx
I'm working on an update to the to_timedelta docs to document this behavior |
Thanks for the reply. Sorry, I would like to ask before the issue is closed. Do you no longer consider supporting the delta calculation of the month? I thought I no longer need to import dateutil every time. |
Correct me if I'm wrong; based on the replies on that issue, I guess the largest supported unit is a week now (?). One reason is months can have different lengths, 28 to 31 days; which one should we pick? It's ambiguous! |
Timedelta are fixed time representations. You can simply use offsets for any real date begin/end manipulatinos which is why they exist. see https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects I thought we deprecated M, Y here but maybe not. I'll repurpose this issue to be a doc one if you'd like to submit a PR to update. |
@selasley, you're already working on a PR I guess you might want to comment the word "take" to assign this issue to yourself. |
I submitted PR #34979. Haven't submitted often so I'm not 100% sure I'm doing it correctly. Comments and improvements are welcome. Using M, y or Y for the units argument in to_datetime raises a ValueError in pandas 1.0.5 and in the 1.1.0 master branch. They are accepted in the arg argument in both versions but their behavior has confused some users. M and Y are no longer listed as accepted units in the docstring for to_timedelta in the 1.1 master branch. The PR is an attempt to document the behavior of M and Y in the arg argument.
|
I'm getting confused too, I believe having |
closed by #34979 |
…dev#34968) (pandas-dev#34979) * DOC: Add notes about M and Y to to_timedelata documentation. (pandas-dev#34968) * DOC: Update notes about M and Y to to_timedelata documentation. (pandas-dev#34968) * DOC: Add notes about M and Y to to_timedelata documentation. (pandas-dev#34968)
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
The documentation in version 1.0.5 is described as follows:
Since in such a particular order, it should be understood as year, month, and week.
But running my code gives the result of a minute for 'M'. However, 'Y' produces the correct parsing result.
I've seen some discussion there about parameters optimization, and whatever the outcome of the discussion, you shouldn't continue to place this bug here, please either change the function or change the documentation.
And perhaps you might consider separating to_datedelta api to reduce complexity.
Thanks.
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1127.10.1.el7.x86_64
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.5
numpy : 1.18.1
The text was updated successfully, but these errors were encountered: