Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions parcels/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,3 @@
from sklearn.cluster import KMeans # type: ignore[no-redef]
except ModuleNotFoundError:
pass


def add_note(e: Exception, note: str, *, before=False) -> Exception: # TODO: Remove once py3.10 support is dropped
"""Implements something similar to PEP 678 but for python <3.11.

https://stackoverflow.com/a/75549200/15545258
"""
args = e.args
if not args:
arg0 = note
else:
arg0 = f"{note}\n{args[0]}" if before else f"{args[0]}\n{note}"
e.args = (arg0,) + args[1:]
return e
4 changes: 1 addition & 3 deletions parcels/_datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import numpy as np
import xarray as xr

from parcels._compat import add_note

_SUPPORTED_ATTR_TYPES = int | float | str | np.ndarray


Expand Down Expand Up @@ -34,7 +32,7 @@ def assert_common_attrs_equal(
else:
assert d1[key] == d2[key], f"{d1[key]} != {d2[key]}"
except AssertionError as e:
add_note(e, f"error on key {key!r}")
e.add_note(f"error on key {key!r}")
raise


Expand Down
3 changes: 1 addition & 2 deletions parcels/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import xarray as xr
from uxarray.grid.neighbors import _barycentric_coordinates

from parcels._compat import add_note
from parcels._typing import (
Mesh,
VectorType,
Expand Down Expand Up @@ -409,7 +408,7 @@ def _interpolate(self, time: datetime, z, y, x, ei):
return val

except (FieldSamplingError, FieldOutOfBoundError, FieldOutOfBoundSurfaceError) as e:
e = add_note(e, f"Error interpolating field '{self.name}'.", before=True)
e.add_note(f"Error interpolating field '{self.name}'.")
raise e

def _check_velocitysampling(self):
Expand Down
14 changes: 0 additions & 14 deletions tests/test_compat.py

This file was deleted.

Loading