33
33
from pandas ._libs import Timestamp , iNaT , lib
34
34
from pandas ._typing import (
35
35
Axis ,
36
- Dtype ,
37
36
FilePathOrBuffer ,
38
37
FrameOrSeries ,
39
38
JSONSerializable ,
@@ -200,22 +199,10 @@ class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin):
200
199
def __init__ (
201
200
self ,
202
201
data : BlockManager ,
203
- axes : Optional [List [Index ]] = None ,
204
202
copy : bool = False ,
205
- dtype : Optional [Dtype ] = None ,
206
203
attrs : Optional [Mapping [Optional [Hashable ], Any ]] = None ,
207
- fastpath : bool = False ,
208
204
):
209
-
210
- if not fastpath :
211
- if dtype is not None :
212
- data = data .astype (dtype )
213
- elif copy :
214
- data = data .copy ()
215
-
216
- if axes is not None :
217
- for i , ax in enumerate (axes ):
218
- data = data .reindex_axis (ax , axis = i )
205
+ # copy kwarg is retained for mypy compat, is not used
219
206
220
207
object .__setattr__ (self , "_is_copy" , None )
221
208
object .__setattr__ (self , "_data" , data )
@@ -226,12 +213,13 @@ def __init__(
226
213
attrs = dict (attrs )
227
214
object .__setattr__ (self , "_attrs" , attrs )
228
215
229
- def _init_mgr (self , mgr , axes = None , dtype = None , copy = False ):
216
+ @classmethod
217
+ def _init_mgr (cls , mgr , axes = None , dtype = None , copy = False ):
230
218
""" passed a manager and a axes dict """
231
219
for a , axe in axes .items ():
232
220
if axe is not None :
233
221
mgr = mgr .reindex_axis (
234
- axe , axis = self ._get_block_manager_axis (a ), copy = False
222
+ axe , axis = cls ._get_block_manager_axis (a ), copy = False
235
223
)
236
224
237
225
# make a copy if explicitly requested
@@ -262,7 +250,8 @@ def attrs(self) -> Dict[Optional[Hashable], Any]:
262
250
def attrs (self , value : Mapping [Optional [Hashable ], Any ]) -> None :
263
251
self ._attrs = dict (value )
264
252
265
- def _validate_dtype (self , dtype ):
253
+ @classmethod
254
+ def _validate_dtype (cls , dtype ):
266
255
""" validate the passed dtype """
267
256
if dtype is not None :
268
257
dtype = pandas_dtype (dtype )
@@ -271,7 +260,7 @@ def _validate_dtype(self, dtype):
271
260
if dtype .kind == "V" :
272
261
raise NotImplementedError (
273
262
"compound dtypes are not implemented "
274
- f"in the { type ( self ) .__name__ } constructor"
263
+ f"in the { cls .__name__ } constructor"
275
264
)
276
265
277
266
return dtype
@@ -324,8 +313,9 @@ def _construct_axes_dict(self, axes=None, **kwargs):
324
313
d .update (kwargs )
325
314
return d
326
315
316
+ @classmethod
327
317
def _construct_axes_from_arguments (
328
- self , args , kwargs , require_all : bool = False , sentinel = None
318
+ cls , args , kwargs , require_all : bool = False , sentinel = None
329
319
):
330
320
"""
331
321
Construct and returns axes if supplied in args/kwargs.
@@ -339,7 +329,7 @@ def _construct_axes_from_arguments(
339
329
"""
340
330
# construct the args
341
331
args = list (args )
342
- for a in self ._AXIS_ORDERS :
332
+ for a in cls ._AXIS_ORDERS :
343
333
344
334
# look for a argument by position
345
335
if a not in kwargs :
@@ -349,7 +339,7 @@ def _construct_axes_from_arguments(
349
339
if require_all :
350
340
raise TypeError ("not enough/duplicate arguments specified!" )
351
341
352
- axes = {a : kwargs .pop (a , sentinel ) for a in self ._AXIS_ORDERS }
342
+ axes = {a : kwargs .pop (a , sentinel ) for a in cls ._AXIS_ORDERS }
353
343
return axes , kwargs
354
344
355
345
@classmethod
@@ -495,7 +485,7 @@ def ndim(self) -> int:
495
485
return self ._data .ndim
496
486
497
487
@property
498
- def size (self ):
488
+ def size (self ) -> int :
499
489
"""
500
490
Return an int representing the number of elements in this object.
501
491
@@ -3660,7 +3650,7 @@ def get(self, key, default=None):
3660
3650
return default
3661
3651
3662
3652
@property
3663
- def _is_view (self ):
3653
+ def _is_view (self ) -> bool_t :
3664
3654
"""Return boolean indicating if self is view of another array """
3665
3655
return self ._data .is_view
3666
3656
@@ -5176,12 +5166,12 @@ def _consolidate(self, inplace: bool_t = False):
5176
5166
return self ._constructor (cons_data ).__finalize__ (self )
5177
5167
5178
5168
@property
5179
- def _is_mixed_type (self ):
5169
+ def _is_mixed_type (self ) -> bool_t :
5180
5170
f = lambda : self ._data .is_mixed_type
5181
5171
return self ._protect_consolidate (f )
5182
5172
5183
5173
@property
5184
- def _is_numeric_mixed_type (self ):
5174
+ def _is_numeric_mixed_type (self ) -> bool_t :
5185
5175
f = lambda : self ._data .is_numeric_mixed_type
5186
5176
return self ._protect_consolidate (f )
5187
5177
0 commit comments