@@ -987,7 +987,7 @@ def reindex(self, *args, **kwargs):
987987
988988 # construct the args
989989 axes , kwargs = self ._construct_axes_from_arguments (args , kwargs )
990- method = kwargs .get ('method' )
990+ method = com . _clean_fill_method ( kwargs .get ('method' ) )
991991 level = kwargs .get ('level' )
992992 copy = kwargs .get ('copy' , True )
993993 limit = kwargs .get ('limit' )
@@ -1003,11 +1003,15 @@ def reindex(self, *args, **kwargs):
10031003 except :
10041004 pass
10051005
1006- # perform the reindex on the axes
1007- if copy and not com ._count_not_none (* axes .values ()):
1008- return self .copy ()
1006+ # if all axes that are requested to reindex are equal, then only copy if indicated
1007+ # must have index names equal here as well as values
1008+ if all ([ self ._get_axis (axis ).identical (ax ) for axis , ax in axes .items () if ax is not None ]):
1009+ if copy :
1010+ return self .copy ()
1011+ return self
10091012
1010- return self ._reindex_axes (axes , level , limit , method , fill_value , copy , takeable = takeable )
1013+ # perform the reindex on the axes
1014+ return self ._reindex_axes (axes , level , limit , method , fill_value , copy , takeable = takeable )._propogate_attributes (self )
10111015
10121016 def _reindex_axes (self , axes , level , limit , method , fill_value , copy , takeable = False ):
10131017 """ perform the reinxed for all the axes """
@@ -1025,7 +1029,8 @@ def _reindex_axes(self, axes, level, limit, method, fill_value, copy, takeable=F
10251029 new_index , indexer = self ._get_axis (a ).reindex (
10261030 labels , level = level , limit = limit , takeable = takeable )
10271031 obj = obj ._reindex_with_indexers (
1028- {axis : [labels , indexer ]}, method , fill_value , copy )
1032+ {axis : [new_index , indexer ]}, method = method , fill_value = fill_value ,
1033+ limit = limit , copy = copy )
10291034
10301035 return obj
10311036
@@ -1077,23 +1082,29 @@ def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
10771082
10781083 axis_name = self ._get_axis_name (axis )
10791084 axis_values = self ._get_axis (axis_name )
1085+ method = com ._clean_fill_method (method )
10801086 new_index , indexer = axis_values .reindex (labels , method , level ,
10811087 limit = limit , copy_if_needed = True )
1082- return self ._reindex_with_indexers ({axis : [new_index , indexer ]}, method , fill_value , copy )
1088+ return self ._reindex_with_indexers ({axis : [new_index , indexer ]}, method = method , fill_value = fill_value ,
1089+ limit = limit , copy = copy )._propogate_attributes (self )
10831090
1084- def _reindex_with_indexers (self , reindexers , method = None , fill_value = np .nan , copy = False ):
1091+ def _reindex_with_indexers (self , reindexers , method = None , fill_value = np .nan , limit = None , copy = False ):
10851092
10861093 # reindex doing multiple operations on different axes if indiciated
10871094 new_data = self ._data
10881095 for axis in sorted (reindexers .keys ()):
10891096 index , indexer = reindexers [axis ]
10901097 baxis = self ._get_block_manager_axis (axis )
10911098
1099+ if index is None :
1100+ continue
1101+ index = _ensure_index (index )
1102+
10921103 # reindex the axis
10931104 if method is not None :
10941105 new_data = new_data .reindex_axis (
1095- index , method = method , axis = baxis ,
1096- fill_value = fill_value , copy = copy )
1106+ index , indexer = indexer , method = method , axis = baxis ,
1107+ fill_value = fill_value , limit = limit , copy = copy )
10971108
10981109 elif indexer is not None :
10991110 # TODO: speed up on homogeneous DataFrame objects
@@ -1409,7 +1420,8 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
14091420 limit : int, default None
14101421 Maximum size gap to forward or backward fill
14111422 downcast : dict, default is None, a dict of item->dtype of what to
1412- downcast if possible
1423+ downcast if possible, or the string 'infer' which will try to
1424+ downcast to an appropriate equal type (e.g. float64 to int64 if possible)
14131425
14141426 See also
14151427 --------
@@ -1428,21 +1440,28 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
14281440 if axis + 1 > self ._AXIS_LEN :
14291441 raise ValueError (
14301442 "invalid axis passed for object type {0}" .format (type (self )))
1443+ method = com ._clean_fill_method (method )
14311444
14321445 if value is None :
14331446 if method is None :
14341447 raise ValueError ('must specify a fill method or value' )
14351448 if self ._is_mixed_type and axis == 1 :
14361449 if inplace :
14371450 raise NotImplementedError ()
1438- return self .T .fillna (method = method , limit = limit ).T
1451+ result = self .T .fillna (method = method , limit = limit ).T
1452+
1453+ # need to downcast here because of all of the transposes
1454+ result ._data = result ._data .downcast ()
1455+
1456+ return result
14391457
14401458 method = com ._clean_fill_method (method )
14411459 new_data = self ._data .interpolate (method = method ,
14421460 axis = axis ,
14431461 limit = limit ,
14441462 inplace = inplace ,
1445- coerce = True )
1463+ coerce = True ,
1464+ downcast = downcast )
14461465 else :
14471466 if method is not None :
14481467 raise ValueError ('cannot specify both a fill method and value' )
@@ -1472,13 +1491,13 @@ def fillna(self, value=None, method=None, axis=0, inplace=False,
14721491 else :
14731492 return self ._constructor (new_data )
14741493
1475- def ffill (self , axis = 0 , inplace = False , limit = None ):
1494+ def ffill (self , axis = 0 , inplace = False , limit = None , downcast = None ):
14761495 return self .fillna (method = 'ffill' , axis = axis , inplace = inplace ,
1477- limit = limit )
1496+ limit = limit , downcast = downcast )
14781497
1479- def bfill (self , axis = 0 , inplace = False , limit = None ):
1498+ def bfill (self , axis = 0 , inplace = False , limit = None , downcast = None ):
14801499 return self .fillna (method = 'bfill' , axis = axis , inplace = inplace ,
1481- limit = limit )
1500+ limit = limit , downcast = downcast )
14821501
14831502 def replace (self , to_replace = None , value = None , inplace = False , limit = None ,
14841503 regex = False , method = None , axis = None ):
@@ -2030,6 +2049,7 @@ def align(self, other, join='outer', axis=None, level=None, copy=True,
20302049 Aligned objects
20312050 """
20322051 from pandas import DataFrame , Series
2052+ method = com ._clean_fill_method (method )
20332053
20342054 if isinstance (other , DataFrame ):
20352055 return self ._align_frame (other , join = join , axis = axis , level = level ,
0 commit comments