File tree Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -513,6 +513,8 @@ Bug Fixes
513
513
- Fix a bug when indexing with ``np.nan `` via ``iloc/loc `` (:issue: `5016 `)
514
514
- Fixed a bug where low memory c parser could create different types in different
515
515
chunks of the same file. Now coerces to numerical type or raises warning. (:issue: `3866 `)
516
+ - Fix a bug where reshaping a ``Series `` to its own shape raised ``TypeError `` (:issue: `4554 `)
517
+ and other reshaping issues.
516
518
517
519
pandas 0.12.0
518
520
-------------
Original file line number Diff line number Diff line change @@ -697,18 +697,21 @@ def repeat(self, reps):
697
697
new_values = self .values .repeat (reps )
698
698
return self ._constructor (new_values , index = new_index , name = self .name )
699
699
700
- def reshape (self , newshape , order = 'C' ):
700
+ def reshape (self , * args , ** kwargs ):
701
701
"""
702
702
See numpy.ndarray.reshape
703
703
"""
704
- if order not in ['C' , 'F' ]:
705
- raise TypeError (
706
- "must specify a tuple / singular length to reshape" )
707
-
708
- if isinstance (newshape , tuple ) and len (newshape ) > 1 :
709
- return self .values .reshape (newshape , order = order )
704
+ if len (args ) == 1 and hasattr (args [0 ], '__iter__' ):
705
+ shape = args [0 ]
710
706
else :
711
- return ndarray .reshape (self , newshape , order )
707
+ shape = args
708
+
709
+ if tuple (shape ) == self .shape :
710
+ # XXX ignoring the "order" keyword.
711
+ return self
712
+
713
+ return self .values .reshape (shape , ** kwargs )
714
+
712
715
713
716
def get (self , label , default = None ):
714
717
"""
Original file line number Diff line number Diff line change @@ -1045,12 +1045,16 @@ def test_basic_getitem_setitem_corner(self):
1045
1045
[5 , slice (None , None )], 2 )
1046
1046
1047
1047
def test_reshape_non_2d (self ):
1048
+ # GH 4554
1048
1049
x = Series (np .random .random (201 ), name = 'x' )
1049
- self .assertRaises ( TypeError , x .reshape , ( len ( x ),) )
1050
+ self .assertTrue ( x .reshape ( x . shape ,) is x )
1050
1051
1051
1052
# GH 2719
1052
1053
a = Series ([1 , 2 , 3 , 4 ])
1053
- self .assertRaises (TypeError , a .reshape , 2 , 2 )
1054
+ result = a .reshape (2 , 2 )
1055
+ expected = a .values .reshape (2 , 2 )
1056
+ np .testing .assert_array_equal (result , expected )
1057
+ self .assertTrue (type (result ) is type (expected ))
1054
1058
1055
1059
def test_reshape_2d_return_array (self ):
1056
1060
x = Series (np .random .random (201 ), name = 'x' )
You can’t perform that action at this time.
0 commit comments