Skip to content

Commit 9255589

Browse files
author
tp
committed
update deprecation of .as_matrix
1 parent 7fd4b71 commit 9255589

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Diff for: doc/source/whatsnew/v0.22.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Deprecations
8282
~~~~~~~~~~~~
8383

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

8888
.. _whatsnew_0220.prior_deprecations:

Diff for: pandas/core/generic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3736,7 +3736,7 @@ def _get_bool_data(self):
37363736
def as_matrix(self, columns=None):
37373737
"""
37383738
DEPRECATED: This method will be removed in a future version.
3739-
Use :meth:`NDFrame.values` instead.
3739+
Use :meth:`DataFrame.values` instead.
37403740
37413741
Convert the frame to its Numpy-array representation.
37423742
@@ -3773,8 +3773,8 @@ def as_matrix(self, columns=None):
37733773
--------
37743774
pandas.DataFrame.values
37753775
"""
3776-
warnings.warn("This method will be removed in a future version. "
3777-
"Use ``.values`` instead.")
3776+
warnings.warn(".as_matrix will be removed in a future version. "
3777+
"Use .values instead.", FutureWarning, stacklevel=2)
37783778
self._consolidate_inplace()
37793779
if self._AXIS_REVERSED:
37803780
return self._data.as_matrix(columns).T

Diff for: pandas/tests/frame/test_api.py

+7
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,13 @@ def test_values(self):
369369
self.frame.values[:, 0] = 5.
370370
assert (self.frame.values[:, 0] == 5).all()
371371

372+
def test_as_matrix_deprecated(self):
373+
# GH18458
374+
with tm.assert_produces_warning(FutureWarning):
375+
result = self.frame.as_matrix()
376+
expected = self.frame.values
377+
tm.assert_numpy_array_equal(result, expected)
378+
372379
def test_deepcopy(self):
373380
cp = deepcopy(self.frame)
374381
series = cp['A']

0 commit comments

Comments
 (0)