Skip to content

Commit

Permalink
Merge pull request #3127 from jreback/reshape
Browse files Browse the repository at this point in the history
BUG: GH2719, fixed reshape on a Series with invalid input
  • Loading branch information
jreback committed Mar 21, 2013
2 parents 8fc9d7d + 61a704f commit 4d3e34e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RELEASE.rst
Expand Up @@ -201,6 +201,7 @@ pandas 0.11.0
- Fixed missing tick bars on scatter_matrix plot (GH3063_)
- Fixed bug in Timestamp(d,tz=foo) when d is date() rather then datetime() (GH2993_)
- series.plot(kind='bar') now respects pylab color schem (GH3115_)
- Fixed bug in reshape if not passed correct input, now raises TypeError (GH2719_)

.. _GH2758: https://github.com/pydata/pandas/issues/2758
.. _GH2809: https://github.com/pydata/pandas/issues/2809
Expand All @@ -220,6 +221,7 @@ pandas 0.11.0
.. _GH622: https://github.com/pydata/pandas/issues/622
.. _GH797: https://github.com/pydata/pandas/issues/797
.. _GH2681: https://github.com/pydata/pandas/issues/2681
.. _GH2719: https://github.com/pydata/pandas/issues/2719
.. _GH2746: https://github.com/pydata/pandas/issues/2746
.. _GH2747: https://github.com/pydata/pandas/issues/2747
.. _GH2751: https://github.com/pydata/pandas/issues/2751
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/series.py
Expand Up @@ -923,6 +923,9 @@ def reshape(self, newshape, order='C'):
"""
See numpy.ndarray.reshape
"""
if order not in ['C','F']:
raise TypeError("must specify a tuple / singular length to reshape")

if isinstance(newshape, tuple) and len(newshape) > 1:
return self.values.reshape(newshape, order=order)
else:
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/test_series.py
Expand Up @@ -932,6 +932,10 @@ def test_reshape_non_2d(self):
x = Series(np.random.random(201), name='x')
self.assertRaises(TypeError, x.reshape, (len(x),))

# GH 2719
a = Series([1,2,3,4])
self.assertRaises(TypeError,a.reshape, 2, 2)

def test_reshape_2d_return_array(self):
x = Series(np.random.random(201), name='x')
result = x.reshape((-1, 1))
Expand Down

0 comments on commit 4d3e34e

Please sign in to comment.