Skip to content

open_mfdataarray with float-type tolerance raises exception #54

@martijnende

Description

@martijnende

Calling open_mfdataarray (or similar) with e.g. tolerance=1.0 raises:

File ~/miniconda3/envs/nami/lib/python3.12/site-packages/xdas/core/routines.py:731, in concatenate(objs, dim, tolerance, virtual, verbose)
    729 if dim_has_coords:
    730     if hasattr(coord, "simplify"):
--> 731         coord = coord.simplify(tolerance)
    732     else:
    733         if tolerance is not None:

File ~/miniconda3/envs/nami/lib/python3.12/site-packages/xdas/core/coordinates.py:854, in InterpCoordinate.simplify(self, tolerance)
    852     else:
    853         tolerance = 0.0
--> 854 tie_indices, tie_values = douglas_peucker(
    855     self.tie_indices, self.tie_values, tolerance
    856 )
    857 return self.__class__(
    858     dict(tie_indices=tie_indices, tie_values=tie_values), self.dim
    859 )

File ~/miniconda3/envs/nami/lib/python3.12/site-packages/xdas/core/coordinates.py:1049, in douglas_peucker(x, y, epsilon)
   1047 dmax = d[index]
   1048 index += start
-> 1049 if dmax > epsilon:
   1050     stack.append([start, index + 1])
   1051     stack.append([index, stop])

UFuncTypeError: ufunc 'greater' did not contain a loop with signature matching types (<class 'numpy.dtypes.TimeDelta64DType'>, <class 'numpy.dtypes._PyFloatDType'>) -> None

I guess that douglas_peucker really wants epsilon to be a timedelta. A quick fix would be to promote epsilon to a np.timedelta64 object here, or otherwise manipulate tolerance here.

Note, this behaviour could be specific to the NumPy version (== 2.3.5), which may have permitted timedelta-float comparisons in previous versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions