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

Snapping error when plotting timedelta data #8

Closed
sco1 opened this issue Oct 18, 2024 · 0 comments · Fixed by #12
Closed

Snapping error when plotting timedelta data #8

sco1 opened this issue Oct 18, 2024 · 0 comments · Fixed by #12
Labels
bug Something isn't working

Comments

@sco1
Copy link
Owner

sco1 commented Oct 18, 2024

e.g. when using the flexible window where the xdata is a timedelta array:

numpy._core._exceptions._UFuncNoLoopError: ufunc 'greater' did not contain a loop with signature matching types (<class 'numpy.dtypes.Float64DType'>, <class 'numpy.dtypes.TimeDelta64DType'>) -> None
numpy.exceptions.DTypePromotionError: The DType <class 'numpy.dtypes.Float64DType'> could not be promoted by <class 'numpy.dtypes.TimeDelta64DType'>. This means that no common DType exists for the given inputs. For example they cannot be stored in a single array unless the dtype is `object`. The full list of DTypes is: (<class 'numpy.dtypes.Float64DType'>, <class 'numpy.dtypes.TimeDelta64DType'>)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "...\.venv\Lib\site-packages\matplotlib\cbook.py", line 298, in process
    func(*args, **kwargs)
  File "...\.venv\Lib\site-packages\matplotlib_window\base.py", line 275, in on_motion
    new_pos = limit_drag(self.snap_to.get_xdata(), event.xdata)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\matplotlib_window\base.py", line 195, in limit_drag
    if query > max_val:
       ^^^^^^^^^^^^^^^
numpy._core._exceptions._UFuncNoLoopError: ufunc 'greater' did not contain a loop with signature matching types (<class 'numpy.dtypes.Float64DType'>, <class 'numpy.dtypes.TimeDelta64DType'>) -> None

Simple numpy reproducer:

import numpy as np

from matplotlib_window.window import flexible_window


xdata = np.arange('2005-02', '2005-03', dtype='datetime64[D]') - np.datetime64("2005-02")
ydata = np.arange(0, 28)

l_bound, r_bound = flexible_window(x_data=xdata, y_data=ydata, position=2, window_width=4)
@sco1 sco1 added the bug Something isn't working label Oct 18, 2024
sco1 added a commit that referenced this issue Dec 30, 2024
@sco1 sco1 mentioned this issue Dec 30, 2024
@sco1 sco1 closed this as completed in #12 Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant