MCPcopy
hub / github.com/pandas-dev/pandas / check_results

Method check_results

pandas/tests/test_nanops.py:256–293  ·  view source on GitHub ↗
(self, targ, res, axis, check_dtype=True)

Source from the content-addressed store, hash-verified

254 nanops._USE_BOTTLENECK = use_bn
255
256 def check_results(self, targ, res, axis, check_dtype=True):
257 res = getattr(res, "asm8", res)
258
259 if (
260 axis != 0
261 and hasattr(targ, "shape")
262 and targ.ndim
263 and targ.shape != res.shape
264 ):
265 res = np.split(res, [targ.shape[0]], axis=0)[0]
266
267 try:
268 tm.assert_almost_equal(targ, res, check_dtype=check_dtype)
269 except AssertionError:
270 # handle timedelta dtypes
271 if hasattr(targ, "dtype") and targ.dtype == "m8[ns]":
272 raise
273
274 # There are sometimes rounding errors with
275 # complex and object dtypes.
276 # If it isn't one of those, re-raise the error.
277 if not hasattr(res, "dtype") or res.dtype.kind not in ["c", "O"]:
278 raise
279 # convert object dtypes to something that can be split into
280 # real and imaginary parts
281 if res.dtype.kind == "O":
282 if targ.dtype.kind != "O":
283 res = res.astype(targ.dtype)
284 else:
285 cast_dtype = "c16" if hasattr(np, "complex128") else "f8"
286 res = res.astype(cast_dtype)
287 targ = targ.astype(cast_dtype)
288 # there should never be a case where numpy returns an object
289 # but nanops doesn't, so make that an exception
290 elif targ.dtype.kind == "O":
291 raise
292 tm.assert_almost_equal(np.real(targ), np.real(res), check_dtype=check_dtype)
293 tm.assert_almost_equal(np.imag(targ), np.imag(res), check_dtype=check_dtype)
294
295 def check_fun_data(
296 self,

Callers 1

check_fun_dataMethod · 0.95

Calls 2

splitMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected