Skip to content

Commit

Permalink
Merge pull request #525 from mhvk/numpy-2.0-safeguard
Browse files Browse the repository at this point in the history
BUG: avoid numpy deprecation warnings in __array__
  • Loading branch information
mhvk authored Aug 22, 2024
2 parents 93b7bd6 + 98fba66 commit 26bb924
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
4.2.1 (unreleased)
==================

Bug fixes
---------

- Avoid numpy>=2.0 deprecation warnings being raised in the ``__array__()``
methods of ``Payload`` and ``Frame.__array__()``. [#525]

4.2 (2024-07-17)
================

Expand Down
6 changes: 3 additions & 3 deletions baseband/base/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ def fill_value(self):
def fill_value(self, fill_value):
self._fill_value = fill_value

def __array__(self, dtype=None):
def __array__(self, dtype=None, copy=None):
"""Interface to arrays."""
if dtype is None or dtype == self.dtype:
if not copy and (dtype is None or dtype == self.dtype):
return self.data
else:
return self.data.astype(dtype)
return self.data.astype(dtype, copy=True)

# Header behaves as a dictionary, while Payload can be indexed/sliced.
# Let frame behave appropriately.
Expand Down
6 changes: 3 additions & 3 deletions baseband/base/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ def fromdata(cls, data, header=None, bps=2):
return cls(words, sample_shape=sample_shape, bps=bps,
complex_data=complex_data)

def __array__(self, dtype=None):
def __array__(self, dtype=None, copy=None):
"""Interface to arrays."""
if dtype is None or dtype == self.dtype:
if not copy and (dtype is None or dtype == self.dtype):
return self.data
else:
return self.data.astype(dtype)
return self.data.astype(dtype, copy=True)

@property
def nbytes(self):
Expand Down

0 comments on commit 26bb924

Please sign in to comment.