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

jointplot with kind="hex" fails with datetime64[ns] #3664

Open
fynnkroeger opened this issue Mar 25, 2024 · 1 comment
Open

jointplot with kind="hex" fails with datetime64[ns] #3664

fynnkroeger opened this issue Mar 25, 2024 · 1 comment

Comments

@fynnkroeger
Copy link

Minimal example:

import seaborn as sns
import numpy as np
dates = np.array(["2023-01-01", "2023-01-02", "2023-01-03"], dtype="datetime64[ns]")
sns.jointplot(x=dates, y=[1, 2, 3], kind="hex")

Error:

Traceback (most recent call last):
  File "/.../seaborn_bug.py", line 21, in <module>
    sns.jointplot(x=dates, y=[1, 2, 3], kind="hex")
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/seaborn/axisgrid.py", line 2307, in jointplot
    x_bins = min(_freedman_diaconis_bins(grid.x), 50)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/seaborn/distributions.py", line 2381, in _freedman_diaconis_bins
    iqr = np.subtract.reduce(np.nanpercentile(a, [75, 25]))
TypeError: the resolved dtypes are not compatible with subtract.reduce. Resolved (dtype('<M8[ns]'), dtype('<M8[ns]'), dtype('<m8[ns]'))

I think this should work, as datetime64[ns] is the default type for datetimes in pandas. It works when I omit kind="hex" or use kind="kde". The error was in version 0.13.2. In 0.11.2 I got a error in the same cases but it was a integer overflow with numpy during conversions.

@athompson1991
Copy link

Hi, I'm not especially experienced in open source development, I think would count as my first contribution, but I just opened a pull request on this. The initial bug was easy enough to sort out, but there were some downstream complications I describe in the pull request. Let me know if this is an appropriate fix, glad to help as best I can.

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

No branches or pull requests

2 participants