@@ -174,8 +174,10 @@ def as_shared_dtype(scalars_or_arrays):
174
174
return [x .astype (out_type , copy = False ) for x in arrays ]
175
175
176
176
177
- def allclose_or_equiv (arr1 , arr2 , rtol = 1e-5 , atol = 1e-8 ):
178
- """Like np.allclose, but also allows values to be NaN in both arrays
177
+ def lazy_array_equiv (arr1 , arr2 ):
178
+ """Like array_equal, but doesn't actually compare values.
179
+ Returns True or False when equality can be determined without computing.
180
+ Returns None when equality cannot determined (e.g. one or both of arr1, arr2 are numpy arrays)
179
181
"""
180
182
arr1 = asarray (arr1 )
181
183
arr2 = asarray (arr2 )
@@ -189,47 +191,34 @@ def allclose_or_equiv(arr1, arr2, rtol=1e-5, atol=1e-8):
189
191
# GH3068
190
192
if arr1 .name == arr2 .name :
191
193
return True
192
- return bool ( isclose ( arr1 , arr2 , rtol = rtol , atol = atol , equal_nan = True ). all ())
194
+ return None
193
195
194
196
195
- def lazy_array_equiv (arr1 , arr2 ):
196
- """Like array_equal, but doesn't actually compare values.
197
- Returns True or False when equality can be determined without computing.
198
- Returns None when equality cannot determined (e.g. one or both of arr1, arr2 are numpy arrays)
197
+ def allclose_or_equiv (arr1 , arr2 , rtol = 1e-5 , atol = 1e-8 ):
198
+ """Like np.allclose, but also allows values to be NaN in both arrays
199
199
"""
200
200
arr1 = asarray (arr1 )
201
201
arr2 = asarray (arr2 )
202
- if arr1 .shape != arr2 .shape :
203
- return False
204
- if (
205
- dask_array
206
- and isinstance (arr1 , dask_array .Array )
207
- and isinstance (arr2 , dask_array .Array )
208
- ):
209
- # GH3068
210
- if arr1 .name == arr2 .name :
211
- return True
202
+ lazy_equiv = lazy_array_equiv (arr1 , arr2 )
203
+ if lazy_equiv is None :
204
+ return bool (isclose (arr1 , arr2 , rtol = rtol , atol = atol , equal_nan = True ).all ())
205
+ else :
206
+ return lazy_equiv
212
207
213
208
214
209
def array_equiv (arr1 , arr2 ):
215
210
"""Like np.array_equal, but also allows values to be NaN in both arrays
216
211
"""
217
212
arr1 = asarray (arr1 )
218
213
arr2 = asarray (arr2 )
219
- if arr1 .shape != arr2 .shape :
220
- return False
221
- if (
222
- dask_array
223
- and isinstance (arr1 , dask_array .Array )
224
- and isinstance (arr2 , dask_array .Array )
225
- ):
226
- # GH3068
227
- if arr1 .name == arr2 .name :
228
- return True
229
- with warnings .catch_warnings ():
230
- warnings .filterwarnings ("ignore" , "In the future, 'NAT == x'" )
231
- flag_array = (arr1 == arr2 ) | (isnull (arr1 ) & isnull (arr2 ))
232
- return bool (flag_array .all ())
214
+ lazy_equiv = lazy_array_equiv (arr1 , arr2 )
215
+ if lazy_equiv is None :
216
+ with warnings .catch_warnings ():
217
+ warnings .filterwarnings ("ignore" , "In the future, 'NAT == x'" )
218
+ flag_array = (arr1 == arr2 ) | (isnull (arr1 ) & isnull (arr2 ))
219
+ return bool (flag_array .all ())
220
+ else :
221
+ return lazy_equiv
233
222
234
223
235
224
def array_notnull_equiv (arr1 , arr2 ):
@@ -238,20 +227,14 @@ def array_notnull_equiv(arr1, arr2):
238
227
"""
239
228
arr1 = asarray (arr1 )
240
229
arr2 = asarray (arr2 )
241
- if arr1 .shape != arr2 .shape :
242
- return False
243
- if (
244
- dask_array
245
- and isinstance (arr1 , dask_array .Array )
246
- and isinstance (arr2 , dask_array .Array )
247
- ):
248
- # GH3068
249
- if arr1 .name == arr2 .name :
250
- return True
251
- with warnings .catch_warnings ():
252
- warnings .filterwarnings ("ignore" , "In the future, 'NAT == x'" )
253
- flag_array = (arr1 == arr2 ) | isnull (arr1 ) | isnull (arr2 )
254
- return bool (flag_array .all ())
230
+ lazy_equiv = lazy_array_equiv (arr1 , arr2 )
231
+ if lazy_equiv is None :
232
+ with warnings .catch_warnings ():
233
+ warnings .filterwarnings ("ignore" , "In the future, 'NAT == x'" )
234
+ flag_array = (arr1 == arr2 ) | isnull (arr1 ) | isnull (arr2 )
235
+ return bool (flag_array .all ())
236
+ else :
237
+ return lazy_equiv
255
238
256
239
257
240
def count (data , axis = None ):
0 commit comments