@@ -304,41 +304,53 @@ class __Datetime(type):
304304 datetime = dt
305305
306306 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 ()
316308
317309 try :
318310 return getattr (cls .datetime , item )
319311 except AttributeError :
320312 raise AttributeError (f"module datetime has no attribute { item } " )
321313
314+ def __instancecheck__ (cls , other ):
315+ if isinstance (other , cls .datetime ):
316+ return True
317+ else :
318+ return False
319+
322320 class __DatetimeSub (metaclass = __Datetime ):
323- def __new__ ( cls , * args , ** kwargs ):
321+ def emitWarning ( ):
324322 import warnings
325323
326324 warnings .warn (
327325 "The pandas.datetime class is deprecated "
328326 "and will be removed from pandas in a future version. "
329327 "Import from datetime instead." ,
330328 FutureWarning ,
331- stacklevel = 2 ,
329+ stacklevel = 3 ,
332330 )
333331
332+ def __new__ (cls , * args , ** kwargs ):
333+ cls .emitWarning ()
334334 from datetime import datetime as dt
335335
336336 return dt (* args , ** kwargs )
337337
338338 datetime = __DatetimeSub
339339
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 ():
342354 import warnings
343355
344356 warnings .warn (
@@ -349,23 +361,14 @@ def __warnSparseArray(self):
349361 stacklevel = 3 ,
350362 )
351363
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+
369372
370373# module level doc-string
371374__doc__ = """
0 commit comments