diff --git a/src/finam/data/grid_tools.py b/src/finam/data/grid_tools.py index a8495678ca4c7d242a435bd04350d86c7f0e605b..031f2c25f2c3cbe601340fd81cdbf071d488cbaf 100644 --- a/src/finam/data/grid_tools.py +++ b/src/finam/data/grid_tools.py @@ -585,7 +585,6 @@ class Grid(GridBase): if isinstance(self, StructuredGrid) != isinstance(other, StructuredGrid): return False - # Might comparison of data_points be sufficient here? return ( self.dim == other.dim and self.crs == other.crs @@ -765,6 +764,22 @@ class StructuredGrid(Grid): np.maximum(dims - 1, 1) if self.data_location == Location.CELLS else dims ) + def __eq__(self, other): + if not isinstance(other, Grid): + return False + + if not isinstance(other, StructuredGrid): + return False + + return ( + self.dim == other.dim + and self.crs == other.crs + and self.order == other.order + and self.data_location == other.data_location + and self.data_shape == other.data_shape + and all(np.allclose(a, b) for a, b in zip(self.axes, other.axes)) + ) + def export_vtk( self, path, diff --git a/src/finam/data/tools.py b/src/finam/data/tools.py index bc315f5233a6f33ccb568a567853ce1a0f8d19d1..35cb8c34a58e15a1b093ca5dbaf362ee6413517b 100644 --- a/src/finam/data/tools.py +++ b/src/finam/data/tools.py @@ -146,7 +146,17 @@ def has_time_axis(xdata, grid): bool Whether the data has a time axis. """ - grid_dim = len(grid.data_shape) if isinstance(grid, Grid) else grid.dim + grid_dim = None + + if isinstance(grid, Grid): + grid_dim = len(grid.data_shape) + elif isinstance(grid, grid_spec.NoGrid): + grid_dim = grid.dim + else: + raise ValueError( + f"Expected type Grid or NoGrid, got {grid.__class__.__name__}." + ) + if xdata.ndim == grid_dim: return False