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

CLN: Drop the .reshape method from classes #18954

Merged
merged 1 commit into from
Dec 27, 2017
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ Removal of prior version deprecations/changes
- :func:`read_csv` has dropped the ``buffer_lines`` parameter (:issue:`13360`)
- :func:`read_csv` has dropped the ``compact_ints`` and ``use_unsigned`` parameters (:issue:`13323`)
- The ``Timestamp`` class has dropped the ``offset`` attribute in favor of ``freq`` (:issue:`13593`)
- The ``Series``, ``Categorical``, and ``Index`` classes have dropped the ``reshape`` method (:issue:`13012`)

.. _whatsnew_0230.performance:

Expand Down
26 changes: 0 additions & 26 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,32 +471,6 @@ def tolist(self):
return [_maybe_box_datetimelike(x) for x in self]
return np.array(self).tolist()

def reshape(self, new_shape, *args, **kwargs):
"""
.. deprecated:: 0.19.0
Calling this method will raise an error in a future release.

An ndarray-compatible method that returns `self` because
`Categorical` instances cannot actually be reshaped.

Parameters
----------
new_shape : int or tuple of ints
A 1-D array of integers that correspond to the new
shape of the `Categorical`. For more information on
the parameter, please refer to `np.reshape`.
"""
warn("reshape is deprecated and will raise "
"in a subsequent release", FutureWarning, stacklevel=2)

nv.validate_reshape(args, kwargs)

# while the 'new_shape' parameter has no effect,
# we should still enforce valid shape parameters
np.reshape(self.codes, new_shape)

return self

@property
def base(self):
""" compat, we are always our own object """
Expand Down
10 changes: 0 additions & 10 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,16 +1190,6 @@ def rename(self, name, inplace=False):
"""
return self.set_names([name], inplace=inplace)

def reshape(self, *args, **kwargs):
"""
NOT IMPLEMENTED: do not call this method, as reshaping is not
supported for Index objects and will raise an error.

Reshape an Index.
"""
raise NotImplementedError("reshaping is not supported "
"for Index objects")

@property
def _has_complex_internals(self):
# to disable groupby tricks in MultiIndex
Expand Down
31 changes: 0 additions & 31 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,37 +910,6 @@ def repeat(self, repeats, *args, **kwargs):
return self._constructor(new_values,
index=new_index).__finalize__(self)

def reshape(self, *args, **kwargs):
"""
.. deprecated:: 0.19.0
Calling this method will raise an error. Please call
``.values.reshape(...)`` instead.

return an ndarray with the values shape
if the specified shape matches exactly the current shape, then
return self (for compat)

See also
--------
numpy.ndarray.reshape
"""
warnings.warn("reshape is deprecated and will raise "
"in a subsequent release. Please use "
".values.reshape(...) instead", FutureWarning,
stacklevel=2)

if len(args) == 1 and hasattr(args[0], '__iter__'):
shape = args[0]
else:
shape = args

if tuple(shape) == self.shape:
# XXX ignoring the "order" keyword.
nv.validate_reshape(tuple(), kwargs)
return self

return self._values.reshape(shape, **kwargs)

def get_value(self, label, takeable=False):
"""
Quickly retrieve single value at passed index label
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,12 +1684,6 @@ def test_take_fill_value(self):
with pytest.raises(IndexError):
idx.take(np.array([1, -5]))

def test_reshape_raise(self):
msg = "reshaping is not supported"
idx = pd.Index([0, 1, 2])
tm.assert_raises_regex(NotImplementedError, msg,
idx.reshape, idx.shape)

def test_reindex_preserves_name_if_target_is_list_or_ndarray(self):
# GH6552
idx = pd.Index([0, 1, 2])
Expand Down
35 changes: 0 additions & 35 deletions pandas/tests/reshape/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,41 +476,6 @@ def test_reshaping_panel_categorical(self):
index=p.major_axis.set_names('major'))
tm.assert_frame_equal(result, expected)

def test_reshape_categorical(self):
cat = Categorical([], categories=["a", "b"])
tm.assert_produces_warning(FutureWarning, cat.reshape, 0)

with tm.assert_produces_warning(FutureWarning):
cat = Categorical([], categories=["a", "b"])
tm.assert_categorical_equal(cat.reshape(0), cat)

with tm.assert_produces_warning(FutureWarning):
cat = Categorical([], categories=["a", "b"])
tm.assert_categorical_equal(cat.reshape((5, -1)), cat)

with tm.assert_produces_warning(FutureWarning):
cat = Categorical(["a", "b"], categories=["a", "b"])
tm.assert_categorical_equal(cat.reshape(cat.shape), cat)

with tm.assert_produces_warning(FutureWarning):
cat = Categorical(["a", "b"], categories=["a", "b"])
tm.assert_categorical_equal(cat.reshape(cat.size), cat)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
msg = "can only specify one unknown dimension"
cat = Categorical(["a", "b"], categories=["a", "b"])
tm.assert_raises_regex(ValueError, msg, cat.reshape, (-2, -1))

def test_reshape_categorical_numpy(self):
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
cat = Categorical(["a", "b"], categories=["a", "b"])
tm.assert_categorical_equal(np.reshape(cat, cat.shape), cat)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
msg = "the 'order' parameter is not supported"
tm.assert_raises_regex(ValueError, msg, np.reshape,
cat, cat.shape, order='F')


class TestMakeAxisDummies(object):

Expand Down
60 changes: 0 additions & 60 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,66 +1542,6 @@ def test_shift_categorical(self):
assert_index_equal(s.values.categories, sp1.values.categories)
assert_index_equal(s.values.categories, sn2.values.categories)

def test_reshape_deprecate(self):
x = Series(np.random.random(10), name='x')
tm.assert_produces_warning(FutureWarning, x.reshape, x.shape)

def test_reshape_non_2d(self):
# see gh-4554
with tm.assert_produces_warning(FutureWarning):
x = Series(np.random.random(201), name='x')
assert x.reshape(x.shape, ) is x

# see gh-2719
with tm.assert_produces_warning(FutureWarning):
a = Series([1, 2, 3, 4])
result = a.reshape(2, 2)
expected = a.values.reshape(2, 2)
tm.assert_numpy_array_equal(result, expected)
assert isinstance(result, type(expected))

def test_reshape_2d_return_array(self):
x = Series(np.random.random(201), name='x')

with tm.assert_produces_warning(FutureWarning):
result = x.reshape((-1, 1))
assert not isinstance(result, Series)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result2 = np.reshape(x, (-1, 1))
assert not isinstance(result2, Series)

with tm.assert_produces_warning(FutureWarning):
result = x[:, None]
expected = x.reshape((-1, 1))
tm.assert_almost_equal(result, expected)

def test_reshape_bad_kwarg(self):
a = Series([1, 2, 3, 4])

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
msg = "'foo' is an invalid keyword argument for this function"
tm.assert_raises_regex(
TypeError, msg, a.reshape, (2, 2), foo=2)

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
msg = r"reshape\(\) got an unexpected keyword argument 'foo'"
tm.assert_raises_regex(
TypeError, msg, a.reshape, a.shape, foo=2)

def test_numpy_reshape(self):
a = Series([1, 2, 3, 4])

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = np.reshape(a, (2, 2))
expected = a.values.reshape(2, 2)
tm.assert_numpy_array_equal(result, expected)
assert isinstance(result, type(expected))

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = np.reshape(a, a.shape)
tm.assert_series_equal(result, a)

def test_unstack(self):
from numpy import nan

Expand Down