Skip to content

CLN use pd.Timestamp for single element in converter #49148

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

Merged
merged 4 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Period

Plotting
^^^^^^^^
-
- ``ax.set_xlim`` was sometimes raising ``UserWarning`` which users couldn't address due to ``set_xlim`` not accepting parsing arguments - the converter now uses :func:`Timestamp` instead (:issue:`49148`)
-

Groupby/resample/rolling
Expand Down
4 changes: 1 addition & 3 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ def _to_ordinalf(tm: pydt.time) -> float:

def time2num(d):
if isinstance(d, str):
parsed = tools.to_datetime(d)
if not isinstance(parsed, datetime):
raise ValueError(f"Could not parse time {d}")
parsed = Timestamp(d)
Copy link
Member

Choose a reason for hiding this comment

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

This probably changes error messages? If yes, should add a whatsnew

Copy link
Member

Choose a reason for hiding this comment

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

i think this also makes the check/raise on the next two lines unnecesary

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah good call, looks like they're uncovered as it is anyway https://app.codecov.io/gh/pandas-dev/pandas/blob/main/pandas/plotting/_matplotlib/converter.py

return _to_ordinalf(parsed.time())
if isinstance(d, pydt.time):
return _to_ordinalf(d)
Expand Down