19
19
the versions in the later versions of pandas.
20
20
"""
21
21
22
- import operator
23
- from typing import Any
24
22
25
- import numpy
26
23
import packaging .version
27
24
import pandas
28
- from pandas .api .types import is_integer
29
25
import pandas .compat .numpy .function
30
26
import pandas .core .nanops
31
27
36
32
nanany = pandas .core .nanops .nanany
37
33
nanmax = pandas .core .nanops .nanmax
38
34
nanmin = pandas .core .nanops .nanmin
35
+ nanmedian = pandas .core .nanops .nanmedian
39
36
numpy_validate_all = pandas .compat .numpy .function .validate_all
40
37
numpy_validate_any = pandas .compat .numpy .function .validate_any
41
38
numpy_validate_max = pandas .compat .numpy .function .validate_max
42
39
numpy_validate_min = pandas .compat .numpy .function .validate_min
40
+ numpy_validate_median = pandas .compat .numpy .function .validate_median
43
41
44
- if pandas_release >= (1 , 3 ):
45
- nanmedian = pandas .core .nanops .nanmedian
46
- numpy_validate_median = pandas .compat .numpy .function .validate_median
47
42
48
-
49
- def import_default (module_name , force = False , default = None ):
43
+ def import_default (module_name , default = None ):
50
44
"""
51
45
Provide an implementation for a class or function when it can't be imported
52
46
@@ -57,16 +51,10 @@ def import_default(module_name, force=False, default=None):
57
51
"""
58
52
59
53
if default is None :
60
- return lambda func_or_class : import_default (module_name , force , func_or_class )
61
-
62
- if force :
63
- return default
54
+ return lambda func_or_class : import_default (module_name , func_or_class )
64
55
65
56
name = default .__name__
66
- try :
67
- module = __import__ (module_name , {}, {}, [name ])
68
- except ModuleNotFoundError :
69
- return default
57
+ module = __import__ (module_name , {}, {}, [name ])
70
58
71
59
return getattr (module , name , default )
72
60
@@ -77,105 +65,11 @@ def import_default(module_name, force=False, default=None):
77
65
# 'datetime.date'
78
66
@import_default ("pandas.core.arraylike" )
79
67
class OpsMixin :
80
- def _cmp_method (self , other , op ): # pragma: NO COVER
81
- return NotImplemented
82
-
83
- def __eq__ (self , other ):
84
- return self ._cmp_method (other , operator .eq )
85
-
86
- def __ne__ (self , other ):
87
- return self ._cmp_method (other , operator .ne )
88
-
89
- def __lt__ (self , other ):
90
- return self ._cmp_method (other , operator .lt )
91
-
92
- def __le__ (self , other ):
93
- return self ._cmp_method (other , operator .le )
94
-
95
- def __gt__ (self , other ):
96
- return self ._cmp_method (other , operator .gt )
97
-
98
- def __ge__ (self , other ):
99
- return self ._cmp_method (other , operator .ge )
100
-
101
- __add__ = __radd__ = __sub__ = lambda self , other : NotImplemented
68
+ pass
102
69
103
70
104
71
# TODO: use public API once pandas 1.5 / 2.x is released.
105
72
# See: https://github.com/pandas-dev/pandas/pull/45544
106
- @import_default ("pandas.core.arrays._mixins" , pandas_release < ( 1 , 3 ) )
73
+ @import_default ("pandas.core.arrays._mixins" )
107
74
class NDArrayBackedExtensionArray (pandas .core .arrays .base .ExtensionArray ):
108
- def __init__ (self , values , dtype ):
109
- assert isinstance (values , numpy .ndarray )
110
- self ._ndarray = values
111
- self ._dtype = dtype
112
-
113
- @classmethod
114
- def _from_backing_data (cls , data ):
115
- return cls (data , data .dtype )
116
-
117
- def __getitem__ (self , index ):
118
- value = self ._ndarray [index ]
119
- if is_integer (index ):
120
- return self ._box_func (value )
121
- return self .__class__ (value , self ._dtype )
122
-
123
- def __setitem__ (self , index , value ):
124
- self ._ndarray [index ] = self ._validate_setitem_value (value )
125
-
126
- def __len__ (self ):
127
- return len (self ._ndarray )
128
-
129
- @property
130
- def shape (self ):
131
- return self ._ndarray .shape
132
-
133
- @property
134
- def ndim (self ) -> int :
135
- return self ._ndarray .ndim
136
-
137
- @property
138
- def size (self ) -> int :
139
- return self ._ndarray .size
140
-
141
- @property
142
- def nbytes (self ) -> int :
143
- return self ._ndarray .nbytes
144
-
145
- def copy (self ):
146
- return self [:]
147
-
148
- def repeat (self , n ):
149
- return self .__class__ (self ._ndarray .repeat (n ), self ._dtype )
150
-
151
- def take (
152
- self ,
153
- indices ,
154
- * ,
155
- allow_fill : bool = False ,
156
- fill_value : Any = None ,
157
- axis : int = 0 ,
158
- ):
159
- from pandas .core .algorithms import take
160
-
161
- if allow_fill :
162
- fill_value = self ._validate_scalar (fill_value )
163
-
164
- new_data = take (
165
- self ._ndarray ,
166
- indices ,
167
- allow_fill = allow_fill ,
168
- fill_value = fill_value ,
169
- axis = axis ,
170
- )
171
- return self ._from_backing_data (new_data )
172
-
173
- @classmethod
174
- def _concat_same_type (cls , to_concat , axis = 0 ):
175
- dtypes = {str (x .dtype ) for x in to_concat }
176
- if len (dtypes ) != 1 :
177
- raise ValueError ("to_concat must have the same dtype (tz)" , dtypes )
178
-
179
- new_values = [x ._ndarray for x in to_concat ]
180
- new_values = numpy .concatenate (new_values , axis = axis )
181
- return to_concat [0 ]._from_backing_data (new_values ) # type: ignore[arg-type]
75
+ pass
0 commit comments