@@ -556,7 +556,7 @@ def _init_ndarray(self, values, index, columns, dtype=None,
556
556
columns = _ensure_index (columns )
557
557
558
558
return create_block_manager_from_blocks ([ values .T ], [ columns , index ])
559
-
559
+
560
560
def _wrap_array (self , arr , axes , copy = False ):
561
561
index , columns = axes
562
562
return self ._constructor (arr , index = index , columns = columns , copy = copy )
@@ -583,7 +583,7 @@ def axes(self):
583
583
584
584
@property
585
585
def _constructor (self ):
586
- return DataFrame
586
+ return self . __class__
587
587
588
588
@property
589
589
def shape (self ):
@@ -865,15 +865,15 @@ def dot(self, other):
865
865
(lvals .shape , rvals .shape ))
866
866
867
867
if isinstance (other , DataFrame ):
868
- return DataFrame (np .dot (lvals , rvals ),
869
- index = left .index ,
870
- columns = other .columns )
868
+ return self . _constructor (np .dot (lvals , rvals ),
869
+ index = left .index ,
870
+ columns = other .columns )
871
871
elif isinstance (other , Series ):
872
872
return Series (np .dot (lvals , rvals ), index = left .index )
873
873
elif isinstance (rvals , np .ndarray ):
874
874
result = np .dot (lvals , rvals )
875
875
if result .ndim == 2 :
876
- return DataFrame (result , index = left .index )
876
+ return self . _constructor (result , index = left .index )
877
877
else :
878
878
return Series (result , index = left .index )
879
879
else : # pragma: no cover
@@ -912,7 +912,7 @@ def from_dict(cls, data, orient='columns', dtype=None):
912
912
elif orient != 'columns' : # pragma: no cover
913
913
raise ValueError ('only recognize index or columns for orient' )
914
914
915
- return DataFrame (data , index = index , columns = columns , dtype = dtype )
915
+ return cls (data , index = index , columns = columns , dtype = dtype )
916
916
917
917
def to_dict (self , outtype = 'dict' ):
918
918
"""
@@ -979,15 +979,15 @@ def from_records(cls, data, index=None, exclude=None, columns=None,
979
979
980
980
if com .is_iterator (data ):
981
981
if nrows == 0 :
982
- return DataFrame ()
982
+ return cls ()
983
983
984
984
try :
985
985
if py3compat .PY3 :
986
986
first_row = next (data )
987
987
else :
988
988
first_row = data .next ()
989
989
except StopIteration :
990
- return DataFrame (index = index , columns = columns )
990
+ return cls (index = index , columns = columns )
991
991
992
992
dtype = None
993
993
if hasattr (first_row , 'dtype' ) and first_row .dtype .names :
@@ -1077,7 +1077,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None,
1077
1077
mgr = _arrays_to_mgr (arrays , arr_columns , result_index ,
1078
1078
columns )
1079
1079
1080
- return DataFrame (mgr )
1080
+ return cls (mgr )
1081
1081
1082
1082
def to_records (self , index = True , convert_datetime64 = True ):
1083
1083
"""
@@ -1815,7 +1815,7 @@ def icol(self, i):
1815
1815
return self ._ixs (i ,axis = 1 )
1816
1816
1817
1817
def _ixs (self , i , axis = 0 , copy = False ):
1818
- """
1818
+ """
1819
1819
i : int, slice, or sequence of integers
1820
1820
axis : int
1821
1821
"""
@@ -1846,7 +1846,7 @@ def _ixs(self, i, axis=0, copy=False):
1846
1846
# icol
1847
1847
else :
1848
1848
1849
- """
1849
+ """
1850
1850
Notes
1851
1851
-----
1852
1852
If slice passed, the resulting data will be a view
@@ -1954,7 +1954,7 @@ def _slice(self, slobj, axis=0, raise_on_error=False):
1954
1954
def _box_item_values (self , key , values ):
1955
1955
items = self .columns [self .columns .get_loc (key )]
1956
1956
if values .ndim == 2 :
1957
- return DataFrame (values .T , columns = items , index = self .index )
1957
+ return self . _constructor (values .T , columns = items , index = self .index )
1958
1958
else :
1959
1959
return Series .from_array (values , index = self .index , name = items )
1960
1960
@@ -2125,7 +2125,7 @@ def pop(self, item):
2125
2125
column : Series
2126
2126
"""
2127
2127
return NDFrame .pop (self , item )
2128
-
2128
+
2129
2129
# to support old APIs
2130
2130
@property
2131
2131
def _series (self ):
@@ -2550,7 +2550,8 @@ def _reindex_multi(self, new_index, new_columns, copy, fill_value):
2550
2550
indexer = row_indexer , col_indexer
2551
2551
new_values = com .take_2d_multi (self .values , indexer ,
2552
2552
fill_value = fill_value )
2553
- return DataFrame (new_values , index = new_index , columns = new_columns )
2553
+ return self ._constructor (new_values , index = new_index ,
2554
+ columns = new_columns )
2554
2555
elif row_indexer is not None :
2555
2556
return self ._reindex_with_indexers (new_index , row_indexer ,
2556
2557
None , None , copy , fill_value )
@@ -5060,7 +5061,8 @@ def rank(self, axis=0, numeric_only=None, method='average',
5060
5061
try :
5061
5062
ranks = algos .rank (self .values , axis = axis , method = method ,
5062
5063
ascending = ascending , na_option = na_option )
5063
- return DataFrame (ranks , index = self .index , columns = self .columns )
5064
+ return self ._constructor (ranks , index = self .index ,
5065
+ columns = self .columns )
5064
5066
except TypeError :
5065
5067
numeric_only = True
5066
5068
@@ -5070,7 +5072,7 @@ def rank(self, axis=0, numeric_only=None, method='average',
5070
5072
data = self
5071
5073
ranks = algos .rank (data .values , axis = axis , method = method ,
5072
5074
ascending = ascending , na_option = na_option )
5073
- return DataFrame (ranks , index = data .index , columns = data .columns )
5075
+ return self . _constructor (ranks , index = data .index , columns = data .columns )
5074
5076
5075
5077
def to_timestamp (self , freq = None , how = 'start' , axis = 0 , copy = True ):
5076
5078
"""
@@ -5104,7 +5106,7 @@ def to_timestamp(self, freq=None, how='start', axis=0, copy=True):
5104
5106
else :
5105
5107
raise ValueError ('Axis must be 0 or 1. Got %s' % str (axis ))
5106
5108
5107
- return DataFrame (new_data )
5109
+ return self . _constructor (new_data )
5108
5110
5109
5111
def to_period (self , freq = None , axis = 0 , copy = True ):
5110
5112
"""
@@ -5139,7 +5141,7 @@ def to_period(self, freq=None, axis=0, copy=True):
5139
5141
else :
5140
5142
raise ValueError ('Axis must be 0 or 1. Got %s' % str (axis ))
5141
5143
5142
- return DataFrame (new_data )
5144
+ return self . _constructor (new_data )
5143
5145
5144
5146
#----------------------------------------------------------------------
5145
5147
# Deprecated stuff
@@ -5221,14 +5223,17 @@ def where(self, cond, other=NA, inplace=False, try_cast=False, raise_on_error=Tr
5221
5223
if other .shape != self .shape :
5222
5224
raise ValueError ('other must be the same shape as self '
5223
5225
'when an ndarray' )
5224
- other = DataFrame (other , self .index , self .columns )
5226
+ other = self . _constructor (other , self .index , self .columns )
5225
5227
5226
5228
if inplace :
5227
- # we may have different type blocks come out of putmask, so reconstruct the block manager
5229
+ # we may have different type blocks come out of putmask, so
5230
+ # reconstruct the block manager
5228
5231
self ._data = self ._data .putmask (cond ,other ,inplace = True )
5229
5232
5230
5233
else :
5231
- new_data = self ._data .where (other , cond , raise_on_error = raise_on_error , try_cast = try_cast )
5234
+ new_data = self ._data .where (other , cond ,
5235
+ raise_on_error = raise_on_error ,
5236
+ try_cast = try_cast )
5232
5237
5233
5238
return self ._constructor (new_data )
5234
5239
0 commit comments