Skip to content

Commit 4d3e34e

Browse files
committed
Merge pull request #3127 from jreback/reshape
BUG: GH2719, fixed reshape on a Series with invalid input
2 parents 8fc9d7d + 61a704f commit 4d3e34e

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

RELEASE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pandas 0.11.0
201201
- Fixed missing tick bars on scatter_matrix plot (GH3063_)
202202
- Fixed bug in Timestamp(d,tz=foo) when d is date() rather then datetime() (GH2993_)
203203
- series.plot(kind='bar') now respects pylab color schem (GH3115_)
204+
- Fixed bug in reshape if not passed correct input, now raises TypeError (GH2719_)
204205

205206
.. _GH2758: https://github.com/pydata/pandas/issues/2758
206207
.. _GH2809: https://github.com/pydata/pandas/issues/2809
@@ -220,6 +221,7 @@ pandas 0.11.0
220221
.. _GH622: https://github.com/pydata/pandas/issues/622
221222
.. _GH797: https://github.com/pydata/pandas/issues/797
222223
.. _GH2681: https://github.com/pydata/pandas/issues/2681
224+
.. _GH2719: https://github.com/pydata/pandas/issues/2719
223225
.. _GH2746: https://github.com/pydata/pandas/issues/2746
224226
.. _GH2747: https://github.com/pydata/pandas/issues/2747
225227
.. _GH2751: https://github.com/pydata/pandas/issues/2751

pandas/core/series.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,9 @@ def reshape(self, newshape, order='C'):
923923
"""
924924
See numpy.ndarray.reshape
925925
"""
926+
if order not in ['C','F']:
927+
raise TypeError("must specify a tuple / singular length to reshape")
928+
926929
if isinstance(newshape, tuple) and len(newshape) > 1:
927930
return self.values.reshape(newshape, order=order)
928931
else:

pandas/tests/test_series.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,10 @@ def test_reshape_non_2d(self):
932932
x = Series(np.random.random(201), name='x')
933933
self.assertRaises(TypeError, x.reshape, (len(x),))
934934

935+
# GH 2719
936+
a = Series([1,2,3,4])
937+
self.assertRaises(TypeError,a.reshape, 2, 2)
938+
935939
def test_reshape_2d_return_array(self):
936940
x = Series(np.random.random(201), name='x')
937941
result = x.reshape((-1, 1))

0 commit comments

Comments
 (0)