Skip to content

Snapping error when plotting timedelta data #8

@sco1

Description

@sco1

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions