@@ -304,41 +304,53 @@ class __Datetime(type):
304
304
datetime = dt
305
305
306
306
def __getattr__ (cls , item ):
307
- import warnings
308
-
309
- warnings .warn (
310
- "The pandas.datetime class is deprecated "
311
- "and will be removed from pandas in a future version. "
312
- "Import from datetime instead." ,
313
- FutureWarning ,
314
- stacklevel = 2 ,
315
- )
307
+ cls .emitWarning ()
316
308
317
309
try :
318
310
return getattr (cls .datetime , item )
319
311
except AttributeError :
320
312
raise AttributeError (f"module datetime has no attribute { item } " )
321
313
314
+ def __instancecheck__ (cls , other ):
315
+ if isinstance (other , cls .datetime ):
316
+ return True
317
+ else :
318
+ return False
319
+
322
320
class __DatetimeSub (metaclass = __Datetime ):
323
- def __new__ ( cls , * args , ** kwargs ):
321
+ def emitWarning ( ):
324
322
import warnings
325
323
326
324
warnings .warn (
327
325
"The pandas.datetime class is deprecated "
328
326
"and will be removed from pandas in a future version. "
329
327
"Import from datetime instead." ,
330
328
FutureWarning ,
331
- stacklevel = 2 ,
329
+ stacklevel = 3 ,
332
330
)
333
331
332
+ def __new__ (cls , * args , ** kwargs ):
333
+ cls .emitWarning ()
334
334
from datetime import datetime as dt
335
335
336
336
return dt (* args , ** kwargs )
337
337
338
338
datetime = __DatetimeSub
339
339
340
- class __SparseArray (pandas .core .arrays .sparse .SparseArray ):
341
- def __warnSparseArray (self ):
340
+ class __SparseArray (type ):
341
+
342
+ from pandas .core .arrays .sparse import SparseArray as sa
343
+
344
+ SparseArray = sa
345
+
346
+ def __instancecheck__ (cls , other ):
347
+ if isinstance (other , cls .SparseArray ):
348
+ return True
349
+ else :
350
+ return False
351
+
352
+ class __SparseArraySub (metaclass = __SparseArray ):
353
+ def emitWarning ():
342
354
import warnings
343
355
344
356
warnings .warn (
@@ -349,23 +361,14 @@ def __warnSparseArray(self):
349
361
stacklevel = 3 ,
350
362
)
351
363
352
- def __init__ (
353
- self ,
354
- data ,
355
- sparse_index = None ,
356
- index = None ,
357
- fill_value = None ,
358
- kind = "integer" ,
359
- dtype = None ,
360
- copy = False ,
361
- ):
362
- self .__warnSparseArray ()
363
- super ().__init__ (data , sparse_index , index , fill_value , kind , dtype , copy )
364
-
365
- def __getattr__ (self , name ):
366
- return super ().__getattribute__ (name )
367
-
368
- SparseArray = __SparseArray
364
+ def __new__ (cls , * args , ** kwargs ):
365
+ cls .emitWarning ()
366
+ from pandas .core .arrays .sparse import SparseArray as sa
367
+
368
+ return sa (* args , ** kwargs )
369
+
370
+ SparseArray = __SparseArraySub
371
+
369
372
370
373
# module level doc-string
371
374
__doc__ = """
0 commit comments