Skip to content

Commit

Permalink
update deprecation of .as_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
tp committed Nov 24, 2017
1 parent 7fd4b71 commit 9255589
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Deprecations
~~~~~~~~~~~~

- ``Series.from_array`` and ``SparseSeries.from_array`` are deprecated. Use the normal constructor ``Series(..)`` and ``SparseSeries(..)`` instead (:issue:`18213`).
- ``NDFrame.as_matrix`` is deprecated. Use ``NDFrame.values`` instead (:issue:`18458`).
- ``DataFrame.as_matrix`` is deprecated. Use ``DataFrame.values`` instead (:issue:`18458`).
-

.. _whatsnew_0220.prior_deprecations:
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3736,7 +3736,7 @@ 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.
Use :meth:`DataFrame.values` instead.
Convert the frame to its Numpy-array representation.
Expand Down Expand Up @@ -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(".as_matrix will be removed in a future version. "
"Use .values instead.", FutureWarning, stacklevel=2)
self._consolidate_inplace()
if self._AXIS_REVERSED:
return self._data.as_matrix(columns).T
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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']
Expand Down

0 comments on commit 9255589

Please sign in to comment.