8000 Add dtype/copy args to internal testing class · matplotlib/matplotlib@5b2efbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 5b2efbc

Browse files
committed
Add dtype/copy args to internal testing class
1 parent 9618fc6 commit 5b2efbc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/matplotlib/tests/test_units.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,16 @@ class Kernel:
282282
def __init__(self, array):
283283
self._array = np.asanyarray(array)
284284

285-
def __array__(self):
286-
return self._array
285+
def __array__(self, dtype=None, copy=None):
286+
if dtype is not None and dtype != self._array.dtype:
287+
if copy is not None and not copy:
288+
raise ValueError(
289+
f"Converting array from {self._array.dtype} to "
290+
f"{dtype} requires a copy"
291+
)
292+
293+
arr = np.asarray(self._array, dtype=dtype)
294+
return (arr if not copy else np.copy(arr))
287295

288296
@property
289297
def shape(self):

0 commit comments

Comments
 (0)
0