-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
DEPR: Deprecate NDFrame.as_matrix #18458
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3484,7 +3484,7 @@ def replace_list(self, src_list, dest_list, inplace=False, regex=False, | |
mgr = self | ||
|
||
# figure out our mask a-priori to avoid repeated replacements | ||
values = self.as_matrix() | ||
values = self.as_array() | ||
|
||
def comp(s): | ||
if isna(s): | ||
|
@@ -3670,7 +3670,21 @@ def copy(self, deep=True, mgr=None): | |
return self.apply('copy', axes=new_axes, deep=deep, | ||
do_integrity_check=False) | ||
|
||
def as_matrix(self, transpose=False, items=None): | ||
def as_array(self, transpose=False, items=None): | ||
"""Convert the blockmanager data into an numpy array. | ||
|
||
Parameters | ||
---------- | ||
transpose : boolean, default False | ||
If True, transpose the return array | ||
items : list of strings or None | ||
Names of block items that will be included in the returned | ||
array. ``None`` means that all block items will be used | ||
|
||
Returns | ||
------- | ||
arr : ndarray | ||
""" | ||
if len(self.blocks) == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a doc-string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
arr = np.empty(self.shape, dtype=float) | ||
return arr.transpose() if transpose else arr | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,29 +245,29 @@ def test_len(self): | |
|
||
def test_values(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you leave one test (or now add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I've added in below |
||
frame = self.frame | ||
mat = frame.values | ||
arr = frame.values | ||
|
||
frameCols = frame.columns | ||
for i, row in enumerate(mat): | ||
frame_cols = frame.columns | ||
for i, row in enumerate(arr): | ||
for j, value in enumerate(row): | ||
col = frameCols[j] | ||
col = frame_cols[j] | ||
if np.isnan(value): | ||
assert np.isnan(frame[col][i]) | ||
else: | ||
assert value == frame[col][i] | ||
|
||
# mixed type | ||
mat = self.mixed_frame[['foo', 'A']].values | ||
assert mat[0, 0] == 'bar' | ||
arr = self.mixed_frame[['foo', 'A']].values | ||
assert arr[0, 0] == 'bar' | ||
|
||
df = self.klass({'real': [1, 2, 3], 'complex': [1j, 2j, 3j]}) | ||
mat = df.values | ||
assert mat[0, 0] == 1j | ||
arr = df.values | ||
assert arr[0, 0] == 1j | ||
|
||
# single block corner case | ||
mat = self.frame[['A', 'B']].values | ||
arr = self.frame[['A', 'B']].values | ||
expected = self.frame.reindex(columns=['A', 'B']).values | ||
assert_almost_equal(mat, expected) | ||
assert_almost_equal(arr, expected) | ||
|
||
def test_transpose(self): | ||
frame = self.frame | ||
|
@@ -372,7 +372,7 @@ def test_values(self): | |
def test_as_matrix_deprecated(self): | ||
# GH18458 | ||
with tm.assert_produces_warning(FutureWarning): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. |
||
result = self.frame.as_matrix() | ||
result = self.frame.as_matrix(columns=self.frame.columns.tolist()) | ||
expected = self.frame.values | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should just return
self.values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning self.values implies that
columns=None
which isn't necessary true for user code.