Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: avoid numpy deprecation warnings in __array__ #525

Merged
merged 1 commit into from
Aug 22, 2024
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
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