@@ -217,19 +217,19 @@ def astype(self, dtype):
217
217
-------
218
218
casted : DataFrame
219
219
"""
220
- return type ( self ) (self ._data , dtype = dtype )
220
+ return self . _constructor (self ._data , dtype = dtype )
221
221
222
222
def _wrap_array (self , arr , axes , copy = False ):
223
223
index , columns = axes
224
- return type ( self ) (arr , index = index , columns = columns , copy = copy )
224
+ return self . _constructor (arr , index = index , columns = columns , copy = copy )
225
225
226
226
@property
227
227
def axes (self ):
228
228
return [self .index , self .columns ]
229
229
230
230
@property
231
231
def _constructor (self ):
232
- return type ( self )
232
+ return DataFrame
233
233
234
234
#----------------------------------------------------------------------
235
235
# Class behavior
@@ -277,7 +277,7 @@ def copy(self):
277
277
"""
278
278
Make a copy of this DataFrame
279
279
"""
280
- return type ( self ) (self ._data .copy ())
280
+ return self . _constructor (self ._data .copy ())
281
281
282
282
#----------------------------------------------------------------------
283
283
# Arithmetic methods
@@ -574,8 +574,8 @@ def transpose(self):
574
574
Returns a DataFrame with the rows/columns switched. Copy of data is not
575
575
made by default
576
576
"""
577
- return type ( self ) (data = self .values .T , index = self .columns ,
578
- columns = self .index , copy = False )
577
+ return self . _constructor (data = self .values .T , index = self .columns ,
578
+ columns = self .index , copy = False )
579
579
T = property (transpose )
580
580
581
581
#----------------------------------------------------------------------
@@ -651,8 +651,8 @@ def __array__(self):
651
651
return self .values
652
652
653
653
def __array_wrap__ (self , result ):
654
- return type ( self ) (result , index = self .index , columns = self .columns ,
655
- copy = False )
654
+ return self . _constructor (result , index = self .index , columns = self .columns ,
655
+ copy = False )
656
656
657
657
#----------------------------------------------------------------------
658
658
# getitem/setitem related
@@ -682,7 +682,7 @@ def __getitem__(self, item):
682
682
"""
683
683
if isinstance (item , slice ):
684
684
new_data = self ._data .get_slice (item , axis = 1 )
685
- return type ( self ) (new_data )
685
+ return self . _constructor (new_data )
686
686
elif isinstance (item , np .ndarray ):
687
687
if len (item ) != len (self .index ):
688
688
raise ValueError ('Item wrong length %d instead of %d!' %
@@ -846,11 +846,11 @@ def _reindex_index(self, new_index, method):
846
846
if new_index is self .index :
847
847
return self .copy ()
848
848
new_data = self ._data .reindex_axis (new_index , method , axis = 1 )
849
- return type ( self ) (new_data )
849
+ return self . _constructor (new_data )
850
850
851
851
def _reindex_columns (self , new_columns ):
852
852
new_data = self ._data .reindex_items (new_columns )
853
- return type ( self ) (new_data )
853
+ return self . _constructor (new_data )
854
854
855
855
def reindex_like (self , other , method = None ):
856
856
"""
@@ -1048,14 +1048,16 @@ def fillna(self, value=None, method='pad'):
1048
1048
series = self ._series
1049
1049
for col , s in series .iteritems ():
1050
1050
result [col ] = s .fillna (method = method , value = value )
1051
- return type (self )(result , index = self .index , columns = self .columns )
1051
+ return self ._constructor (result , index = self .index ,
1052
+ columns = self .columns )
1052
1053
else :
1053
1054
# Float type values
1054
1055
if len (self .columns ) == 0 :
1055
1056
return self
1056
1057
1057
1058
new_data = self ._data .fillna (value )
1058
- return type (self )(new_data , index = self .index , columns = self .columns )
1059
+ return self ._constructor (new_data , index = self .index ,
1060
+ columns = self .columns )
1059
1061
1060
1062
#----------------------------------------------------------------------
1061
1063
# Rename
@@ -1131,7 +1133,7 @@ def _combine_frame(self, other, func, fill_value=None):
1131
1133
# some shortcuts
1132
1134
if fill_value is None :
1133
1135
if not self and not other :
1134
- return type ( self ) (index = new_index )
1136
+ return self . _constructor (index = new_index )
1135
1137
elif not self :
1136
1138
return other * nan
1137
1139
elif not other :
@@ -1164,8 +1166,8 @@ def _combine_frame(self, other, func, fill_value=None):
1164
1166
other_vals [other_mask & mask ] = fill_value
1165
1167
1166
1168
result = func (this_vals , other_vals )
1167
- return type ( self ) (result , index = new_index , columns = new_columns ,
1168
- copy = False )
1169
+ return self . _constructor (result , index = new_index , columns = new_columns ,
1170
+ copy = False )
1169
1171
1170
1172
def _indexed_same (self , other ):
1171
1173
same_index = self .index .equals (other .index )
@@ -1202,8 +1204,8 @@ def _combine_match_index(self, other, func, fill_value=None):
1202
1204
if fill_value is not None :
1203
1205
raise NotImplementedError
1204
1206
1205
- return type ( self ) (func (values .T , other_vals ).T , index = new_index ,
1206
- columns = self .columns , copy = False )
1207
+ return self . _constructor (func (values .T , other_vals ).T , index = new_index ,
1208
+ columns = self .columns , copy = False )
1207
1209
1208
1210
def _combine_match_columns (self , other , func , fill_value = None ):
1209
1211
newCols = self .columns .union (other .index )
@@ -1215,15 +1217,15 @@ def _combine_match_columns(self, other, func, fill_value=None):
1215
1217
if fill_value is not None :
1216
1218
raise NotImplementedError
1217
1219
1218
- return type ( self ) (func (this .values , other ), index = self .index ,
1219
- columns = newCols , copy = False )
1220
+ return self . _constructor (func (this .values , other ), index = self .index ,
1221
+ columns = newCols , copy = False )
1220
1222
1221
1223
def _combine_const (self , other , func ):
1222
1224
if not self :
1223
1225
return self
1224
1226
1225
- return type ( self ) (func (self .values , other ), index = self .index ,
1226
- columns = self .columns , copy = False )
1227
+ return self . _constructor (func (self .values , other ), index = self .index ,
1228
+ columns = self .columns , copy = False )
1227
1229
1228
1230
def _compare_frame (self , other , func ):
1229
1231
if not self ._indexed_same (other ):
@@ -1488,7 +1490,7 @@ def _shift_block(blk, indexer):
1488
1490
new_data = self ._data .copy ()
1489
1491
new_data .axes [1 ] = self .index .shift (periods , offset )
1490
1492
1491
- return type ( self ) (new_data )
1493
+ return self . _constructor (new_data )
1492
1494
1493
1495
def _shift_indexer (self , periods ):
1494
1496
# small reusable utility
@@ -1535,8 +1537,8 @@ def apply(self, func, axis=0, broadcast=False):
1535
1537
1536
1538
if isinstance (func , np .ufunc ):
1537
1539
results = func (self .values )
1538
- return type ( self ) (data = results , index = self .index ,
1539
- columns = self .columns , copy = False )
1540
+ return self . _constructor (data = results , index = self .index ,
1541
+ columns = self .columns , copy = False )
1540
1542
else :
1541
1543
if not broadcast :
1542
1544
return self ._apply_standard (func , axis )
@@ -1692,7 +1694,7 @@ def _join_on(self, other, on):
1692
1694
raise Exception ('%s column not contained in this frame!' % on )
1693
1695
1694
1696
new_data = self ._data .join_on (other ._data , self [on ], axis = 1 )
1695
- return type ( self ) (new_data )
1697
+ return self . _constructor (new_data )
1696
1698
1697
1699
def _join_index (self , other , how ):
1698
1700
join_index = self ._get_join_index (other , how )
@@ -1702,7 +1704,7 @@ def _join_index(self, other, how):
1702
1704
# merge blocks
1703
1705
merged_data = this_data .merge (other_data )
1704
1706
assert (merged_data .axes [1 ] is join_index ) # maybe unnecessary
1705
- return type ( self ) (merged_data )
1707
+ return self . _constructor (merged_data )
1706
1708
1707
1709
def _get_join_index (self , other , how ):
1708
1710
if how == 'left' :
@@ -1797,7 +1799,7 @@ def corr(self):
1797
1799
correl [i , j ] = c
1798
1800
correl [j , i ] = c
1799
1801
1800
- return type ( self ) (correl , index = cols , columns = cols )
1802
+ return self . _constructor (correl , index = cols , columns = cols )
1801
1803
1802
1804
def corrwith (self , other , axis = 0 , drop = False ):
1803
1805
"""
@@ -1867,7 +1869,7 @@ def describe(self):
1867
1869
tmp .quantile (.1 ), tmp .median (),
1868
1870
tmp .quantile (.9 ), tmp .max ()]
1869
1871
1870
- return type ( self ) (data , index = cols_destat , columns = cols )
1872
+ return self . _constructor (data , index = cols_destat , columns = cols )
1871
1873
1872
1874
#----------------------------------------------------------------------
1873
1875
# ndarray-like stats methods
0 commit comments