@@ -1669,7 +1669,8 @@ def lookup(self, row_labels, col_labels):
1669
1669
#----------------------------------------------------------------------
1670
1670
# Reindexing and alignment
1671
1671
1672
- def align (self , other , join = 'outer' , axis = None , level = None , copy = True ):
1672
+ def align (self , other , join = 'outer' , axis = None , level = None , copy = True ,
1673
+ fill_value = None , fill_method = None ):
1673
1674
"""
1674
1675
Align two DataFrame object on their index and columns with the
1675
1676
specified join method for each axis Index
@@ -1683,6 +1684,11 @@ def align(self, other, join='outer', axis=None, level=None, copy=True):
1683
1684
level : int or name
1684
1685
Broadcast across a level, matching Index values on the
1685
1686
passed MultiIndex level
1687
+ copy : boolean, default True
1688
+ Always returns new objects. If copy=False and no reindexing is
1689
+ required then original objects are returned.
1690
+ fill_value : object, default None
1691
+ fill_method : str, default None
1686
1692
1687
1693
Returns
1688
1694
-------
@@ -1691,15 +1697,19 @@ def align(self, other, join='outer', axis=None, level=None, copy=True):
1691
1697
"""
1692
1698
if isinstance (other , DataFrame ):
1693
1699
return self ._align_frame (other , join = join , axis = axis , level = level ,
1694
- copy = copy )
1700
+ copy = copy ,
1701
+ fill_value = fill_value ,
1702
+ fill_method = fill_method )
1695
1703
elif isinstance (other , Series ):
1696
1704
return self ._align_series (other , join = join , axis = axis , level = level ,
1697
- copy = copy )
1705
+ copy = copy ,
1706
+ fill_value = fill_value ,
1707
+ fill_method = fill_method )
1698
1708
else : # pragma: no cover
1699
1709
raise TypeError ('unsupported type: %s' % type (other ))
1700
1710
1701
1711
def _align_frame (self , other , join = 'outer' , axis = None , level = None ,
1702
- copy = True ):
1712
+ copy = True , fill_value = None , fill_method = None ):
1703
1713
# defaults
1704
1714
join_index , join_columns = None , None
1705
1715
ilidx , iridx = None , None
@@ -1721,10 +1731,15 @@ def _align_frame(self, other, join='outer', axis=None, level=None,
1721
1731
join_columns , clidx , copy )
1722
1732
right = other ._reindex_with_indexers (join_index , iridx ,
1723
1733
join_columns , cridx , copy )
1724
- return left , right
1734
+ fill_na = (fill_value is not None ) or (fill_method is not None )
1735
+ if fill_na :
1736
+ return (left .fillna (fill_value , method = fill_method ),
1737
+ right .fillna (fill_value , method = fill_method ))
1738
+ else :
1739
+ return left , right
1725
1740
1726
1741
def _align_series (self , other , join = 'outer' , axis = None , level = None ,
1727
- copy = True ):
1742
+ copy = True , fill_value = None , fill_method = None ):
1728
1743
fdata = self ._data
1729
1744
if axis == 0 :
1730
1745
join_index = self .index
@@ -1753,7 +1768,13 @@ def _align_series(self, other, join='outer', axis=None, level=None,
1753
1768
1754
1769
left_result = DataFrame (fdata )
1755
1770
right_result = other if ridx is None else other .reindex (join_index )
1756
- return left_result , right_result
1771
+
1772
+ fill_na = (fill_value is not None ) or (fill_method is not None )
1773
+ if fill_na :
1774
+ return (left_result .fillna (fill_value , fill_method = fill_method ),
1775
+ right_result .fillna (fill_value , fill_method = fill_method ))
1776
+ else :
1777
+ return left_result , right_result
1757
1778
1758
1779
def reindex (self , index = None , columns = None , method = None , level = None ,
1759
1780
copy = True ):
@@ -4080,18 +4101,6 @@ def _to_sdict(data, columns):
4080
4101
else : # pragma: no cover
4081
4102
raise TypeError ('No logic to handle %s type' % type (data [0 ]))
4082
4103
4083
- def _list_to_sdict (data , columns ):
4084
- if len (data ) > 0 and isinstance (data [0 ], tuple ):
4085
- content = list (lib .to_object_array_tuples (data ).T )
4086
- elif len (data ) > 0 :
4087
- # list of lists
4088
- content = list (lib .to_object_array (data ).T )
4089
- else :
4090
- if columns is None :
4091
- columns = []
4092
- return {}, columns
4093
- return _convert_object_array (content , columns )
4094
-
4095
4104
def _list_of_series_to_sdict (data , columns ):
4096
4105
from pandas .core .index import _get_combined_index
4097
4106
@@ -4117,6 +4126,7 @@ def _list_of_series_to_sdict(data, columns):
4117
4126
else :
4118
4127
return values , columns
4119
4128
4129
+
4120
4130
def _list_of_dict_to_sdict (data , columns ):
4121
4131
if columns is None :
4122
4132
gen = (x .keys () for x in data )
0 commit comments