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

Method test_numeric_only

pandas/tests/series/test_api.py:237–278  ·  view source on GitHub ↗
(self, kernel, has_numeric_only, dtype)

Source from the content-addressed store, hash-verified

235 )
236 @pytest.mark.parametrize("dtype", [bool, int, float, object])
237 def test_numeric_only(self, kernel, has_numeric_only, dtype):
238 # GH#47500
239 ser = Series([0, 1, 1], dtype=dtype)
240 if kernel == "corrwith":
241 args = (ser,)
242 elif kernel == "corr":
243 args = (ser,)
244 elif kernel == "cov":
245 args = (ser,)
246 elif kernel == "nth":
247 args = (0,)
248 elif kernel == "fillna":
249 args = (True,)
250 elif kernel == "fillna":
251 args = ("ffill",)
252 elif kernel == "take":
253 args = ([0],)
254 elif kernel == "quantile":
255 args = (0.5,)
256 else:
257 args = ()
258 method = getattr(ser, kernel)
259 if not has_numeric_only:
260 msg = (
261 "(got an unexpected keyword argument 'numeric_only'"
262 "|too many arguments passed in)"
263 )
264 with pytest.raises(TypeError, match=msg):
265 method(*args, numeric_only=True)
266 elif dtype is object:
267 msg = f"Series.{kernel} does not allow numeric_only=True with non-numeric"
268 with pytest.raises(TypeError, match=msg):
269 method(*args, numeric_only=True)
270 else:
271 result = method(*args, numeric_only=True)
272 expected = method(*args, numeric_only=False)
273 if isinstance(expected, Series):
274 # transformer
275 tm.assert_series_equal(result, expected)
276 else:
277 # reducer
278 assert result == expected

Callers

nothing calls this directly

Calls 3

SeriesClass · 0.90
methodFunction · 0.50
raisesMethod · 0.45

Tested by

no test coverage detected