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

handle deprecation of pandas.Series.dt.to_pydatetime() calls and suppress their FutureWarnings #4379

Merged
merged 2 commits into from
Oct 12, 2023

Conversation

ned2
Copy link
Contributor

@ned2 ned2 commented Oct 11, 2023

As of Pandas 2.1.0, it is deprecating the behaviour of Series.dt.to_pydatetime(), which currently returns a numpy.ndarray, and changing it to return a pandas.Series of Python datetime objects.

https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.to_pydatetime.html

This PR fixes #4363. The issue is that user's consoles are currently spammed with a FutureWarning containing this warning, which they cannot do anything about as the warning is coming inside the Plotly Package.

The fix is to first wrap the output of Series.dt.to_pydatetime() with an np.array() call, so that the code will continue to work when the behaviour change drops. Then secondly, each offending call is put inside a warnings.catch_warnings() context manager that suppresses the FutureWarning only for the contents of the with block.

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • I have added tests (if submitting a new feature or correcting a bug) or
    modified existing tests.
  • For a new feature, I have added documentation examples in an existing or
    new tutorial notebook (please see the doc checklist as well).
  • I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

💃 Looks great, thanks @ned2! Please add a changelog entry and we'll merge.

@ned2
Copy link
Contributor Author

ned2 commented Oct 12, 2023

easy, changelog entry added @alexcjohnson

@alexcjohnson alexcjohnson merged commit 57e4d1d into plotly:master Oct 12, 2023
4 checks passed
danking pushed a commit to danking/hail that referenced this pull request Nov 6, 2023
Plotly relies on behavior that Pandas is deprecating. See plotly/plotly.py#4363 and plotly/plotly.py#4379. The fix (plotly/plotly.py#4379) merged into [main and was released in 5.18.0](plotly/plotly.py@57e4d1d).
danking pushed a commit to danking/hail that referenced this pull request Nov 6, 2023
Plotly relies on behavior that Pandas is deprecating. See plotly/plotly.py#4363 and plotly/plotly.py#4379. The fix (plotly/plotly.py#4379) merged into [main and was released in 5.18.0](plotly/plotly.py@57e4d1d).
danking added a commit to hail-is/hail that referenced this pull request Jan 9, 2024
Plotly relies on behavior that Pandas is deprecated. See
plotly/plotly.py#4363 and
plotly/plotly.py#4379. The fix
(plotly/plotly.py#4379) merged into [main and
was released in
5.18.0](plotly/plotly.py@57e4d1d).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DatetimeProperties.to_pydatetime is deprecated
2 participants