-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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 |
---|---|---|
|
@@ -3735,8 +3735,8 @@ def _get_bool_data(self): | |
|
||
def as_matrix(self, columns=None): | ||
""" | ||
DEPRECATED: This method will be removed in a future version. | ||
Use :meth:`NDFrame.values` instead. | ||
DEPRECATED: as_matrix will be removed in a future version. | ||
Use :meth:`DataFrame.values` instead. | ||
|
||
Convert the frame to its Numpy-array representation. | ||
|
||
|
@@ -3773,8 +3773,8 @@ def as_matrix(self, columns=None): | |
-------- | ||
pandas.DataFrame.values | ||
""" | ||
warnings.warn("This method will be removed in a future version. " | ||
"Use ``.values`` instead.") | ||
warnings.warn("method ``as_matrix`` will be removed in a future version. " | ||
"Use ``values`` instead.", FutureWarning, stacklevel=2) | ||
self._consolidate_inplace() | ||
if self._AXIS_REVERSED: | ||
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 so this should be the same as below (e.g. passing 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, and |
||
return self._data.as_matrix(columns).T | ||
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. this should just return 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. Returning self.values implies that |
||
|
@@ -3797,9 +3797,7 @@ def values(self): | |
will result in a flot64 dtype. | ||
""" | ||
self._consolidate_inplace() | ||
if self._AXIS_REVERSED: | ||
return self._data.as_matrix().T | ||
return self._data.as_matrix() | ||
return self._data.as_matrix(transpose=self._AXIS_REVERSED) | ||
|
||
@property | ||
def _values(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3670,19 +3670,22 @@ def copy(self, deep=True, mgr=None): | |
return self.apply('copy', axes=new_axes, deep=deep, | ||
do_integrity_check=False) | ||
|
||
def as_matrix(self, items=None): | ||
def as_matrix(self, transpose=False, items=None): | ||
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 |
||
return np.empty(self.shape, dtype=float) | ||
arr = np.empty(self.shape, dtype=float) | ||
return arr.transpose() if transpose else arr | ||
|
||
if items is not None: | ||
mgr = self.reindex_axis(items, axis=0) | ||
else: | ||
mgr = self | ||
|
||
if self._is_single_block or not self.is_mixed_type: | ||
return mgr.blocks[0].get_values() | ||
arr = mgr.blocks[0].get_values() | ||
else: | ||
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. change this to 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. Thanks a lot, The issue was actually in the Everything is green now locally and I've pushed that upstream. |
||
return mgr._interleave() | ||
arr = mgr._interleave() | ||
|
||
return arr.transpose() if transpose else arr | ||
|
||
def _interleave(self): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,7 +257,7 @@ def test_values(self): | |
assert value == frame[col][i] | ||
|
||
# mixed type | ||
mat = self.mixed_frame.as_matrix(['foo', 'A']) | ||
mat = self.mixed_frame[['foo', 'A']].values | ||
assert mat[0, 0] == 'bar' | ||
|
||
df = self.klass({'real': [1, 2, 3], 'complex': [1j, 2j, 3j]}) | ||
|
@@ -369,6 +369,13 @@ def test_values(self): | |
self.frame.values[:, 0] = 5. | ||
assert (self.frame.values[:, 0] == 5).all() | ||
|
||
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() | ||
expected = self.frame.values | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def test_deepcopy(self): | ||
cp = deepcopy(self.frame) | ||
series = cp['A'] | ||
|
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.
"method method .as_matrix()...."
"Use .values instead"
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.
I not sure I understand, assume you want the backticks gone. Change uploaded.