@@ -1693,7 +1693,7 @@ def lookup(self, row_labels, col_labels):
1693
1693
# Reindexing and alignment
1694
1694
1695
1695
def align (self , other , join = 'outer' , axis = None , level = None , copy = True ,
1696
- fill_value = None , method = None ):
1696
+ fill_value = np . nan , method = None ):
1697
1697
"""
1698
1698
Align two DataFrame object on their index and columns with the
1699
1699
specified join method for each axis Index
@@ -1710,7 +1710,9 @@ def align(self, other, join='outer', axis=None, level=None, copy=True,
1710
1710
copy : boolean, default True
1711
1711
Always returns new objects. If copy=False and no reindexing is
1712
1712
required then original objects are returned.
1713
- fill_value : object, default None
1713
+ fill_value : scalar, default np.NaN
1714
+ Value to use for missing values. Defaults to NaN, but can be any
1715
+ "compatible" value
1714
1716
method : str, default None
1715
1717
1716
1718
Returns
@@ -1730,7 +1732,7 @@ def align(self, other, join='outer', axis=None, level=None, copy=True,
1730
1732
raise TypeError ('unsupported type: %s' % type (other ))
1731
1733
1732
1734
def _align_frame (self , other , join = 'outer' , axis = None , level = None ,
1733
- copy = True , fill_value = None , method = None ):
1735
+ copy = True , fill_value = np . nan , method = None ):
1734
1736
# defaults
1735
1737
join_index , join_columns = None , None
1736
1738
ilidx , iridx = None , None
@@ -1749,15 +1751,17 @@ def _align_frame(self, other, join='outer', axis=None, level=None,
1749
1751
return_indexers = True )
1750
1752
1751
1753
left = self ._reindex_with_indexers (join_index , ilidx ,
1752
- join_columns , clidx , copy )
1754
+ join_columns , clidx , copy ,
1755
+ fill_value = fill_value )
1753
1756
right = other ._reindex_with_indexers (join_index , iridx ,
1754
- join_columns , cridx , copy )
1755
- fill_na = (fill_value is not None ) or (method is not None )
1756
- if fill_na :
1757
- return (left .fillna (fill_value , method = method ),
1758
- right .fillna (fill_value , method = method ))
1759
- else :
1760
- return left , right
1757
+ join_columns , cridx , copy ,
1758
+ fill_value = fill_value )
1759
+
1760
+ if method is not None :
1761
+ left = left .fillna (method = method )
1762
+ right = right .fillna (method = method )
1763
+
1764
+ return left , right
1761
1765
1762
1766
def _align_series (self , other , join = 'outer' , axis = None , level = None ,
1763
1767
copy = True , fill_value = None , method = None ):
@@ -1798,7 +1802,7 @@ def _align_series(self, other, join='outer', axis=None, level=None,
1798
1802
return left_result , right_result
1799
1803
1800
1804
def reindex (self , index = None , columns = None , method = None , level = None ,
1801
- copy = True ):
1805
+ fill_value = np . nan , copy = True ):
1802
1806
"""Conform DataFrame to new index with optional filling logic, placing
1803
1807
NA/NaN in locations having no value in the previous index. A new object
1804
1808
is produced unless the new index is equivalent to the current one and
@@ -1820,6 +1824,9 @@ def reindex(self, index=None, columns=None, method=None, level=None,
1820
1824
level : int or name
1821
1825
Broadcast across a level, matching Index values on the
1822
1826
passed MultiIndex level
1827
+ fill_value : scalar, default np.NaN
1828
+ Value to use for missing values. Defaults to NaN, but can be any
1829
+ "compatible" value
1823
1830
1824
1831
Examples
1825
1832
--------
@@ -1833,14 +1840,15 @@ def reindex(self, index=None, columns=None, method=None, level=None,
1833
1840
frame = self
1834
1841
1835
1842
if index is not None :
1836
- frame = frame ._reindex_index (index , method , copy , level )
1843
+ frame = frame ._reindex_index (index , method , copy , level , fill_value )
1837
1844
1838
1845
if columns is not None :
1839
- frame = frame ._reindex_columns (columns , copy , level )
1846
+ frame = frame ._reindex_columns (columns , copy , level , fill_value )
1840
1847
1841
1848
return frame
1842
1849
1843
- def reindex_axis (self , labels , axis = 0 , method = None , level = None , copy = True ):
1850
+ def reindex_axis (self , labels , axis = 0 , method = None , level = None , copy = True ,
1851
+ fill_value = np .nan ):
1844
1852
"""Conform DataFrame to new index with optional filling logic, placing
1845
1853
NA/NaN in locations having no value in the previous index. A new object
1846
1854
is produced unless the new index is equivalent to the current one and
@@ -1878,42 +1886,45 @@ def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True):
1878
1886
"""
1879
1887
self ._consolidate_inplace ()
1880
1888
if axis == 0 :
1881
- df = self ._reindex_index (labels , method , copy , level )
1882
- return df
1889
+ return self ._reindex_index (labels , method , copy , level ,
1890
+ fill_value = fill_value )
1883
1891
elif axis == 1 :
1884
- df = self ._reindex_columns (labels , copy , level )
1885
- return df
1892
+ return self ._reindex_columns (labels , copy , level ,
1893
+ fill_value = fill_value )
1886
1894
else : # pragma: no cover
1887
1895
raise ValueError ('Must specify axis=0 or 1' )
1888
1896
1889
- def _reindex_index (self , new_index , method , copy , level ):
1897
+ def _reindex_index (self , new_index , method , copy , level , fill_value = np . nan ):
1890
1898
if level is not None :
1891
1899
assert (isinstance (new_index , MultiIndex ))
1892
1900
new_index , indexer = self .index .reindex (new_index , method , level )
1893
1901
return self ._reindex_with_indexers (new_index , indexer , None , None ,
1894
- copy )
1902
+ copy , fill_value )
1895
1903
1896
- def _reindex_columns (self , new_columns , copy , level ):
1904
+ def _reindex_columns (self , new_columns , copy , level , fill_value = np . nan ):
1897
1905
if level is not None :
1898
1906
assert (isinstance (new_columns , MultiIndex ))
1899
1907
new_columns , indexer = self .columns .reindex (new_columns , level = level )
1900
1908
return self ._reindex_with_indexers (None , None , new_columns , indexer ,
1901
- copy )
1909
+ copy , fill_value )
1902
1910
1903
1911
def _reindex_with_indexers (self , index , row_indexer , columns , col_indexer ,
1904
- copy ):
1912
+ copy , fill_value ):
1905
1913
new_data = self ._data
1906
1914
if row_indexer is not None :
1907
- new_data = new_data .reindex_indexer (index , row_indexer , axis = 1 )
1915
+ new_data = new_data .reindex_indexer (index , row_indexer , axis = 1 ,
1916
+ fill_value = fill_value )
1908
1917
elif index is not None and index is not new_data .axes [1 ]:
1909
1918
new_data = new_data .copy (deep = copy )
1910
1919
new_data .axes [1 ] = index
1911
1920
1912
1921
if col_indexer is not None :
1913
1922
# TODO: speed up on homogeneous DataFrame objects
1914
- new_data = new_data .reindex_indexer (columns , col_indexer , axis = 0 )
1923
+ new_data = new_data .reindex_indexer (columns , col_indexer , axis = 0 ,
1924
+ fill_value = fill_value )
1915
1925
elif columns is not None and columns is not new_data .axes [0 ]:
1916
- new_data = new_data .reindex_items (columns , copy = copy )
1926
+ new_data = new_data .reindex_items (columns , copy = copy ,
1927
+ fill_value = fill_value )
1917
1928
1918
1929
if copy and new_data is self ._data :
1919
1930
new_data = new_data .copy ()
@@ -2361,8 +2372,7 @@ def reorder_levels(self, order, axis=0):
2361
2372
2362
2373
def fillna (self , value = None , method = 'pad' , inplace = False ):
2363
2374
"""
2364
- Fill NA/NaN values using the specified method. Member Series /
2365
- TimeSeries are filled separately
2375
+ Fill NA/NaN values using the specified method
2366
2376
2367
2377
Parameters
2368
2378
----------
@@ -2402,12 +2412,6 @@ def fillna(self, value=None, method='pad', inplace=False):
2402
2412
new_blocks .append (newb )
2403
2413
2404
2414
new_data = BlockManager (new_blocks , self ._data .axes )
2405
-
2406
- # series = self._series
2407
- # for col, s in series.iteritems():
2408
- # result[col] = s.fillna(method=method, value=value)
2409
- # return self._constructor(result, index=self.index,
2410
- # columns=self.columns)
2411
2415
else :
2412
2416
# Float type values
2413
2417
if len (self .columns ) == 0 :
0 commit comments