diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-12-22 15:39:23 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-12-26 08:47:32 +0000 |
commit | 1e08c83a1b84a3b847c101d478814c18adda56f2 (patch) | |
tree | 98a4a15c124f09a910c87a799e825ee20680e35d /numpy/lib/tests/test_histograms.py | |
parent | 59084fa132c244c0ae622cae8f7a58a363eaa7e8 (diff) | |
download | numpy-1e08c83a1b84a3b847c101d478814c18adda56f2.tar.gz |
ENH: Add support for datetimes to histograms
Currently only supported for explicit bins
Diffstat (limited to 'numpy/lib/tests/test_histograms.py')
-rw-r--r-- | numpy/lib/tests/test_histograms.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py index 0986ad16b..58547dc17 100644 --- a/numpy/lib/tests/test_histograms.py +++ b/numpy/lib/tests/test_histograms.py @@ -274,6 +274,31 @@ class TestHistogram(object): h, b = histogram(all_nan, bins=[0, 1]) assert_equal(h.sum(), 0) # nan is not counted + def test_datetime(self): + begin = np.datetime64('2000-01-01', 'D') + offsets = np.array([0, 0, 1, 1, 2, 3, 5, 10, 20]) + bins = np.array([0, 2, 7, 20]) + dates = begin + offsets + date_bins = begin + bins + + td = np.dtype('timedelta64[D]') + + # Results should be the same for integer offsets or datetime values. + # For now, only explicit bins are supported, since linspace does not + # work on datetimes or timedeltas + d_count, d_edge = histogram(dates, bins=date_bins) + t_count, t_edge = histogram(offsets.astype(td), bins=bins.astype(td)) + i_count, i_edge = histogram(offsets, bins=bins) + + assert_equal(d_count, i_count) + assert_equal(t_count, i_count) + + assert_equal((d_edge - begin).astype(int), i_edge) + assert_equal(t_edge.astype(int), i_edge) + + assert_equal(d_edge.dtype, dates.dtype) + assert_equal(t_edge.dtype, td) + class TestHistogramOptimBinNums(object): """ |