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

DatetimeProperties.to_pydatetime is deprecated #4363

Closed
VelizarVESSELINOV opened this issue Sep 17, 2023 · 8 comments · Fixed by #4379
Closed

DatetimeProperties.to_pydatetime is deprecated #4363

VelizarVESSELINOV opened this issue Sep 17, 2023 · 8 comments · Fixed by #4379

Comments

@VelizarVESSELINOV
Copy link

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/_plotly_utils/basevalidators.py:105: FutureWarning:

The behavior of DatetimeProperties.to_pydatetime is deprecated, in a future version this will return a Series containing python datetime objects instead of an ndarray. To retain the old behavior, call np.array on the result

@sp-pablo-losada
Copy link

Same happens here!

@fsadock
Copy link

fsadock commented Sep 21, 2023

It's a pandas issue. To remove the warning try downgrading to 2.0.3 instead of using the new 2.1.0

@ned2
Copy link
Contributor

ned2 commented Oct 6, 2023

After upgrading to the latest Pandas, I'm now seeing this FutureWarning in a bunch of my plots made with Plotly Express that has datetimes. You can suppress the warning in the meantime, but if the behaviour is going to change, Plotly will need to make an appropriate change before this happens.

See the deprecation note at the top here: https://pandas.pydata.org/docs/dev/reference/api/pandas.Series.dt.to_pydatetime.html

It's unfortunate that the recommended approach for restoring the functionality of returning an numpy array is just to wrap the result in np.array, because the FutureWarning will still persist until whenever the behaviour change is implemented. Perhaps an alternative way of generating an array of datetimes could be used instead of using Series.dt.to_pydatetime?

@ned2
Copy link
Contributor

ned2 commented Oct 6, 2023

hey @alexcjohnson how thorny do you think this one is? is there a simple change to a different way of producing numpy arrays that could be swapped over? if so I could be up for submitting a PR.

@alexcjohnson
Copy link
Collaborator

Hmph yeah frustrating that their recommendation does not silence the warning. We could do the same thing Pandas does in their own code and filter the warning out while wrapping in np.asarray. Feels a little risky to me, what if we end up filtering out something else that still matters? I don't see another good option though. Or we could go for the lower-level thing Pandas added to their code ie use the private ser._values.to_pydatetime() which apparently is not deprecated, but that feels even more dangerous.

@ned2
Copy link
Contributor

ned2 commented Oct 7, 2023

The first of those options feels like the best one to me. By using the warnings.catch_warnings() context manager to do the suppressing, it would be localising the risk of a false positive being suppressed to a very small surface area.

Here's a proof of concept for _plotly_utils/basevalidators.py. There's also two other modules I see using Series.dt.to_pydatetime(), but they also look fairly low risk to me.

@alexcjohnson
Copy link
Collaborator

Thanks @ned2 - let's go with that. Your POC looks great (but nd -> np?), and let's include the other modules you found as well!

@ned2
Copy link
Contributor

ned2 commented Oct 11, 2023

great thanks @alexcjohnson. have raised a PR over at #4379. there were a few failing tests but they seemed unrelated, so we can see what happens in CI.

(ah yes oops, copying error from when I moved the change from the monkey-patched installed plotly package I validated it on.)

danking pushed a commit to danking/hail that referenced this issue 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 issue 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 issue 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
5 participants