File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -526,6 +526,19 @@ def ensure_float(arr):
526
526
527
527
return arr
528
528
529
+ def ensure_nansafe (arr ):
530
+ """
531
+ convert int to float
532
+ convert bool to object
533
+ """
534
+ if issubclass (arr .dtype .type , np .integer ):
535
+ arr = arr .astype (float )
536
+
537
+ elif issubclass (arr .dtype .type , np .bool_ ):
538
+ arr = arr .astype (object )
539
+
540
+ return arr
541
+
529
542
def _mut_exclusive (arg1 , arg2 ):
530
543
if arg1 is not None and arg2 is not None :
531
544
raise Exception ('mutually exclusive arguments' )
Original file line number Diff line number Diff line change @@ -3567,7 +3567,7 @@ def _shift_block(blk, indexer):
3567
3567
new_values = blk .values .take (indexer , axis = 1 )
3568
3568
# convert integer to float if necessary. need to do a lot more than
3569
3569
# that, handle boolean etc also
3570
- new_values = com .ensure_float (new_values )
3570
+ new_values = com .ensure_nansafe (new_values )
3571
3571
if periods > 0 :
3572
3572
new_values [:, :periods ] = nan
3573
3573
else :
Original file line number Diff line number Diff line change @@ -4930,6 +4930,15 @@ def test_shift(self):
4930
4930
4931
4931
self .assertRaises (ValueError , ps .shift , freq = 'D' )
4932
4932
4933
+ def test_shift_bool (self ):
4934
+ df = DataFrame ({'high' :[True , False ],
4935
+ 'low' :[False , False ]})
4936
+ rs = df .shift (1 )
4937
+ xp = DataFrame (np .array ([[np .nan , np .nan ],
4938
+ [True , False ]], dtype = object ),
4939
+ columns = ['high' , 'low' ])
4940
+ assert_frame_equal (rs , xp )
4941
+
4933
4942
def test_tshift (self ):
4934
4943
# PeriodIndex
4935
4944
ps = tm .makePeriodFrame ()
You can’t perform that action at this time.
0 commit comments