Skip to content

Commit 6a1a1fe

Browse files
committed
BUG: avoid soon-to-be-deprecated direct mutations of ndarray.shape attributes (7/n, n=7)
1 parent ec7b76f commit 6a1a1fe

File tree

1 file changed

+0
-31
lines changed

1 file changed

+0
-31
lines changed

yt/_maintenance/numpy2_compat.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,9 @@
11
# avoid deprecation warnings in numpy >= 2.0
2-
from dataclasses import dataclass
3-
from importlib.metadata import version
4-
from typing import Literal, TypeAlias
52

63
import numpy as np
7-
from packaging.version import Version
84

95
if hasattr(np, "trapezoid"):
106
# np.trapz is deprecated in numpy 2.0 in favor of np.trapezoid
117
trapezoid = np.trapezoid
128
else:
139
trapezoid = np.trapz # type: ignore # noqa: NPY201
14-
15-
16-
NUMPY_VERSION = Version(version("numpy"))
17-
18-
# list functions that gained support for a copy kwarg at some point since
19-
# our oldest supported numpy version was introduced, and record when that
20-
# support was added
21-
CopyFunc: TypeAlias = Literal["reshape"]
22-
MIN_NUMPY_VERSION: dict[CopyFunc, Version] = {
23-
"reshape": Version("2.1.0"),
24-
}
25-
26-
27-
@dataclass(frozen=True, slots=True)
28-
class CopyKwarg:
29-
value: bool | None
30-
31-
def get(self, f: CopyFunc, /) -> dict[Literal["copy"], bool | None]:
32-
if NUMPY_VERSION >= MIN_NUMPY_VERSION[f]:
33-
return {"copy": self.value}
34-
else:
35-
return {}
36-
37-
38-
COPY_NONE = CopyKwarg(None)
39-
COPY_TRUE = CopyKwarg(True)
40-
COPY_FALSE = CopyKwarg(False)

0 commit comments

Comments
 (0)