@@ -565,7 +565,7 @@ def axes(self):
565
565
566
566
@property
567
567
def _constructor (self ):
568
- return DataFrame
568
+ return self . __class__
569
569
570
570
# Fancy indexing
571
571
_ix = None
@@ -855,15 +855,15 @@ def dot(self, other):
855
855
(lvals .shape , rvals .shape ))
856
856
857
857
if isinstance (other , DataFrame ):
858
- return DataFrame (np .dot (lvals , rvals ),
858
+ return self . _constructor (np .dot (lvals , rvals ),
859
859
index = left .index ,
860
860
columns = other .columns )
861
861
elif isinstance (other , Series ):
862
862
return Series (np .dot (lvals , rvals ), index = left .index )
863
863
elif isinstance (rvals , np .ndarray ):
864
864
result = np .dot (lvals , rvals )
865
865
if result .ndim == 2 :
866
- return DataFrame (result , index = left .index )
866
+ return self . _constructor (result , index = left .index )
867
867
else :
868
868
return Series (result , index = left .index )
869
869
else : # pragma: no cover
@@ -902,7 +902,7 @@ def from_dict(cls, data, orient='columns', dtype=None):
902
902
elif orient != 'columns' : # pragma: no cover
903
903
raise ValueError ('only recognize index or columns for orient' )
904
904
905
- return DataFrame (data , index = index , columns = columns , dtype = dtype )
905
+ return cls (data , index = index , columns = columns , dtype = dtype )
906
906
907
907
def to_dict (self , outtype = 'dict' ):
908
908
"""
@@ -969,15 +969,15 @@ def from_records(cls, data, index=None, exclude=None, columns=None,
969
969
970
970
if com .is_iterator (data ):
971
971
if nrows == 0 :
972
- return DataFrame ()
972
+ return cls ()
973
973
974
974
try :
975
975
if py3compat .PY3 :
976
976
first_row = next (data )
977
977
else :
978
978
first_row = data .next ()
979
979
except StopIteration :
980
- return DataFrame (index = index , columns = columns )
980
+ return cls (index = index , columns = columns )
981
981
982
982
dtype = None
983
983
if hasattr (first_row , 'dtype' ) and first_row .dtype .names :
@@ -1067,7 +1067,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None,
1067
1067
mgr = _arrays_to_mgr (arrays , arr_columns , result_index ,
1068
1068
columns )
1069
1069
1070
- return DataFrame (mgr )
1070
+ return cls (mgr )
1071
1071
1072
1072
def to_records (self , index = True , convert_datetime64 = True ):
1073
1073
"""
@@ -2061,7 +2061,7 @@ def _slice(self, slobj, axis=0):
2061
2061
def _box_item_values (self , key , values ):
2062
2062
items = self .columns [self .columns .get_loc (key )]
2063
2063
if values .ndim == 2 :
2064
- return DataFrame (values .T , columns = items , index = self .index )
2064
+ return self . _constructor (values .T , columns = items , index = self .index )
2065
2065
else :
2066
2066
return Series .from_array (values , index = self .index , name = items )
2067
2067
@@ -2647,7 +2647,7 @@ def _reindex_multi(self, new_index, new_columns, copy, fill_value):
2647
2647
if row_indexer is not None and col_indexer is not None :
2648
2648
new_values = com .take_2d_multi (self .values , row_indexer ,
2649
2649
col_indexer , fill_value = fill_value )
2650
- return DataFrame (new_values , index = new_index , columns = new_columns )
2650
+ return self . _constructor (new_values , index = new_index , columns = new_columns )
2651
2651
elif row_indexer is not None :
2652
2652
return self ._reindex_with_indexers (new_index , row_indexer ,
2653
2653
None , None , copy , fill_value )
@@ -2695,7 +2695,7 @@ def _reindex_with_indexers(self, index, row_indexer, columns, col_indexer,
2695
2695
if copy and new_data is self ._data :
2696
2696
new_data = new_data .copy ()
2697
2697
2698
- return DataFrame (new_data )
2698
+ return self . _constructor (new_data )
2699
2699
2700
2700
def reindex_like (self , other , method = None , copy = True , limit = None ):
2701
2701
"""
@@ -2938,7 +2938,7 @@ def take(self, indices, axis=0):
2938
2938
if self ._is_mixed_type :
2939
2939
if axis == 0 :
2940
2940
new_data = self ._data .take (indices , axis = 1 )
2941
- return DataFrame (new_data )
2941
+ return self . _constructor (new_data )
2942
2942
else :
2943
2943
new_columns = self .columns .take (indices )
2944
2944
return self .reindex (columns = new_columns )
@@ -2952,7 +2952,7 @@ def take(self, indices, axis=0):
2952
2952
else :
2953
2953
new_columns = self .columns .take (indices )
2954
2954
new_index = self .index
2955
- return DataFrame (new_values , index = new_index ,
2955
+ return self . _constructor (new_values , index = new_index ,
2956
2956
columns = new_columns )
2957
2957
2958
2958
#----------------------------------------------------------------------
@@ -4191,7 +4191,7 @@ def _apply_raw(self, func, axis):
4191
4191
4192
4192
# TODO: mixed type case
4193
4193
if result .ndim == 2 :
4194
- return DataFrame (result , index = self .index ,
4194
+ return self . _constructor (result , index = self .index ,
4195
4195
columns = self .columns )
4196
4196
else :
4197
4197
return Series (result , index = self ._get_agg_axis (axis ))
@@ -4622,7 +4622,7 @@ def describe(self, percentile_width=50):
4622
4622
numdata = self ._get_numeric_data ()
4623
4623
4624
4624
if len (numdata .columns ) == 0 :
4625
- return DataFrame (dict ((k , v .describe ())
4625
+ return self . _constructor (dict ((k , v .describe ())
4626
4626
for k , v in self .iteritems ()),
4627
4627
columns = self .columns )
4628
4628
@@ -5006,7 +5006,7 @@ def _get_agg_axis(self, axis_num):
5006
5006
def _get_numeric_data (self ):
5007
5007
if self ._is_mixed_type :
5008
5008
num_data = self ._data .get_numeric_data ()
5009
- return DataFrame (num_data , index = self .index , copy = False )
5009
+ return self . _constructor (num_data , index = self .index , copy = False )
5010
5010
else :
5011
5011
if (self .values .dtype != np .object_ and
5012
5012
not issubclass (self .values .dtype .type , np .datetime64 )):
@@ -5017,7 +5017,7 @@ def _get_numeric_data(self):
5017
5017
def _get_bool_data (self ):
5018
5018
if self ._is_mixed_type :
5019
5019
bool_data = self ._data .get_bool_data ()
5020
- return DataFrame (bool_data , index = self .index , copy = False )
5020
+ return self . _constructor (bool_data , index = self .index , copy = False )
5021
5021
else : # pragma: no cover
5022
5022
if self .values .dtype == np .bool_ :
5023
5023
return self
@@ -5127,7 +5127,7 @@ def rank(self, axis=0, numeric_only=None, method='average',
5127
5127
try :
5128
5128
ranks = algos .rank (self .values , axis = axis , method = method ,
5129
5129
ascending = ascending , na_option = na_option )
5130
- return DataFrame (ranks , index = self .index , columns = self .columns )
5130
+ return self . _constructor (ranks , index = self .index , columns = self .columns )
5131
5131
except TypeError :
5132
5132
numeric_only = True
5133
5133
@@ -5137,7 +5137,7 @@ def rank(self, axis=0, numeric_only=None, method='average',
5137
5137
data = self
5138
5138
ranks = algos .rank (data .values , axis = axis , method = method ,
5139
5139
ascending = ascending , na_option = na_option )
5140
- return DataFrame (ranks , index = data .index , columns = data .columns )
5140
+ return self . _constructor (ranks , index = data .index , columns = data .columns )
5141
5141
5142
5142
def to_timestamp (self , freq = None , how = 'start' , axis = 0 , copy = True ):
5143
5143
"""
@@ -5170,7 +5170,7 @@ def to_timestamp(self, freq=None, how='start', axis=0, copy=True):
5170
5170
else :
5171
5171
raise ValueError ('Axis must be 0 or 1. Got %s' % str (axis ))
5172
5172
5173
- return DataFrame (new_data )
5173
+ return self . _constructor (new_data )
5174
5174
5175
5175
def to_period (self , freq = None , axis = 0 , copy = True ):
5176
5176
"""
@@ -5204,7 +5204,7 @@ def to_period(self, freq=None, axis=0, copy=True):
5204
5204
else :
5205
5205
raise ValueError ('Axis must be 0 or 1. Got %s' % str (axis ))
5206
5206
5207
- return DataFrame (new_data )
5207
+ return self . _constructor (new_data )
5208
5208
5209
5209
#----------------------------------------------------------------------
5210
5210
# Deprecated stuff
0 commit comments