Skip to content

Commit 98fba66

Browse files
committed
BUG: avoid numpy deprecation warnings in __array__
1 parent 93b7bd6 commit 98fba66

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGES.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
4.2.1 (unreleased)
2+
==================
3+
4+
Bug fixes
5+
---------
6+
7+
- Avoid numpy>=2.0 deprecation warnings being raised in the ``__array__()``
8+
methods of ``Payload`` and ``Frame.__array__()``. [#525]
9+
110
4.2 (2024-07-17)
211
================
312

baseband/base/frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ def fill_value(self):
179179
def fill_value(self, fill_value):
180180
self._fill_value = fill_value
181181

182-
def __array__(self, dtype=None):
182+
def __array__(self, dtype=None, copy=None):
183183
"""Interface to arrays."""
184-
if dtype is None or dtype == self.dtype:
184+
if not copy and (dtype is None or dtype == self.dtype):
185185
return self.data
186186
else:
187-
return self.data.astype(dtype)
187+
return self.data.astype(dtype, copy=True)
188188

189189
# Header behaves as a dictionary, while Payload can be indexed/sliced.
190190
# Let frame behave appropriately.

baseband/base/payload.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ def fromdata(cls, data, header=None, bps=2):
181181
return cls(words, sample_shape=sample_shape, bps=bps,
182182
complex_data=complex_data)
183183

184-
def __array__(self, dtype=None):
184+
def __array__(self, dtype=None, copy=None):
185185
"""Interface to arrays."""
186-
if dtype is None or dtype == self.dtype:
186+
if not copy and (dtype is None or dtype == self.dtype):
187187
return self.data
188188
else:
189-
return self.data.astype(dtype)
189+
return self.data.astype(dtype, copy=True)
190190

191191
@property
192192
def nbytes(self):

0 commit comments

Comments
 (0)