MCPcopy Index your code
hub / github.com/numpy/numpy / test_some_nan_values

Method test_some_nan_values

numpy/lib/tests/test_histograms.py:280–302  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

278 np.histogram([np.array(0.5) for i in range(10)] + [.5])
279
280 def test_some_nan_values(self):
281 # gh-7503
282 one_nan = np.array([0, 1, np.nan])
283 all_nan = np.array([np.nan, np.nan])
284
285 # the internal comparisons with NaN give warnings
286 with warnings.catch_warnings():
287 warnings.simplefilter('ignore', RuntimeWarning)
288 # can't infer range with nan
289 assert_raises(ValueError, histogram, one_nan, bins='auto')
290 assert_raises(ValueError, histogram, all_nan, bins='auto')
291
292 # explicit range solves the problem
293 h, b = histogram(one_nan, bins='auto', range=(0, 1))
294 assert_equal(h.sum(), 2) # nan is not counted
295 h, b = histogram(all_nan, bins='auto', range=(0, 1))
296 assert_equal(h.sum(), 0) # nan is not counted
297
298 # as does an explicit set of bins
299 h, b = histogram(one_nan, bins=[0, 1])
300 assert_equal(h.sum(), 2) # nan is not counted
301 h, b = histogram(all_nan, bins=[0, 1])
302 assert_equal(h.sum(), 0) # nan is not counted
303
304 def test_datetime(self):
305 begin = np.datetime64('2000-01-01', 'D')

Callers

nothing calls this directly

Calls 4

assert_raisesFunction · 0.90
histogramFunction · 0.90
assert_equalFunction · 0.90
sumMethod · 0.45

Tested by

no test coverage detected