def test_curve_pandas_timestamps(self): if not pd: raise SkipTest("Pandas not available") dates = pd.date_range('2016-01-01', '2016-01-10', freq='D') curve = Curve((dates, np.random.rand(10))) plot = mpl_renderer.get_plot(curve) self.assertEqual(plot.handles['axis'].get_xlim(), (735964.0, 735973.0))
def test_aggregate_ndoverlay_count_cat_datetimes_microsecond_timebase( self): dates = pd.date_range(start="2016-01-01", end="2016-01-03", freq='1D') xstart = np.datetime64('2015-12-31T23:59:59.723518000', 'us') xend = np.datetime64('2016-01-03T00:00:00.276482000', 'us') curve = Curve((dates, [1, 2, 3])) curve2 = Curve((dates, [3, 2, 1])) ndoverlay = NdOverlay({0: curve, 1: curve2}, 'Cat') imgs = aggregate(ndoverlay, aggregator=ds.count_cat('Cat'), width=2, height=2, x_range=(xstart, xend), dynamic=False) bounds = (np.datetime64('2015-12-31T23:59:59.723518'), 1.0, np.datetime64('2016-01-03T00:00:00.276482'), 3.0) dates = [ np.datetime64('2016-01-01T11:59:59.861759000', ), np.datetime64('2016-01-02T12:00:00.138241000') ] expected = Image((dates, [1.5, 2.5], [[1, 0], [0, 2]]), datatype=['xarray'], bounds=bounds, vdims='Count') expected2 = Image((dates, [1.5, 2.5], [[0, 1], [1, 1]]), datatype=['xarray'], bounds=bounds, vdims='Count') self.assertEqual(imgs[0], expected) self.assertEqual(imgs[1], expected2)
def test_curve_pandas_timestamps(self): dates = pd.date_range('2016-01-01', '2016-01-10', freq='D') curve = Curve((dates, np.random.rand(10))) plot = bokeh_renderer.get_plot(curve) self.assertEqual(plot.handles['x_range'].start, np.datetime64(dt.datetime(2016, 1, 1))) self.assertEqual(plot.handles['x_range'].end, np.datetime64(dt.datetime(2016, 1, 10)))
def test_points_overlay_datetime_hover(self): if pd is None: raise SkipTest("Test requires pandas") obj = NdOverlay({i: Points((list(pd.date_range('2016-01-01', '2016-01-31')), range(31))) for i in range(5)}, kdims=['Test']) opts = {'Points': {'tools': ['hover']}} obj = obj.opts(plot=opts) self._test_hover_info(obj, [('Test', '@{Test}'), ('x', '@{x_dt_strings}'), ('y', '@{y}')])
def test_points_overlay_datetime_hover(self): if pd is None: raise SkipTest("Test requires pandas") obj = NdOverlay({i: Points((list(pd.date_range('2016-01-01', '2016-01-31')), range(31))) for i in range(5)}, kdims=['Test']) opts = {'Points': {'tools': ['hover']}} obj = obj(plot=opts) self._test_hover_info(obj, [('Test', '@{Test}'), ('x', '@{x_dt_strings}'), ('y', '@{y}')])
def test_curve_heterogeneous_datetime_types_with_pd_overlay(self): dates_pd = pd.date_range('2016-01-04', '2016-01-13', freq='D') dates64 = [np.datetime64(dt.datetime(2016,1,i)) for i in range(1, 11)] dates = [dt.datetime(2016,1,i) for i in range(2, 12)] curve_dt64 = Curve((dates64, np.random.rand(10))) curve_dt = Curve((dates, np.random.rand(10))) curve_pd = Curve((dates_pd, np.random.rand(10))) plot = mpl_renderer.get_plot(curve_dt*curve_dt64*curve_pd) self.assertEqual(plot.handles['axis'].get_xlim(), (735964.0, 735976.0))
def test_segments_overlay_datetime_hover(self): if pd is None: raise SkipTest("Test requires pandas") obj = NdOverlay( { i: Segments( (list(pd.date_range('2016-01-01', '2016-01-31')), range(31), pd.date_range('2016-01-02', '2016-02-01'), range(31))) for i in range(5) }, kdims=['Test']).opts({'Segments': { 'tools': ['hover'] }}) tooltips = [('Test', '@{Test}'), ('x0', '@{x0}{%F %T}'), ('y0', '@{y0}'), ('x1', '@{x1}{%F %T}'), ('y1', '@{y1}')] formatters = {'@{x0}': "datetime", '@{x1}': "datetime"} self._test_hover_info(obj, tooltips, formatters=formatters)
def test_curve_heterogeneous_datetime_types_with_pd_overlay(self): dates_pd = pd.date_range('2016-01-04', '2016-01-13', freq='D') dates64 = [np.datetime64(dt.datetime(2016,1,i)) for i in range(1, 11)] dates = [dt.datetime(2016,1,i) for i in range(2, 12)] curve_dt64 = Curve((dates64, np.random.rand(10))) curve_dt = Curve((dates, np.random.rand(10))) curve_pd = Curve((dates_pd, np.random.rand(10))) plot = bokeh_renderer.get_plot(curve_dt*curve_dt64*curve_pd) self.assertEqual(plot.handles['x_range'].start, np.datetime64(dt.datetime(2016, 1, 1))) self.assertEqual(plot.handles['x_range'].end, np.datetime64(dt.datetime(2016, 1, 13)))
def test_aggregate_curve_datetimes(self): dates = pd.date_range(start="2016-01-01", end="2016-01-03", freq='1D') curve = Curve((dates, [1, 2, 3])) img = aggregate(curve, width=2, height=2, dynamic=False) bounds = (np.datetime64('2016-01-01T00:00:00.000000'), 1.0, np.datetime64('2016-01-03T00:00:00.000000'), 3.0) dates = [np.datetime64('2016-01-01T12:00:00.000000000'), np.datetime64('2016-01-02T12:00:00.000000000')] expected = Image((dates, [1.5, 2.5], [[1, 0], [0, 2]]), datatype=['xarray'], bounds=bounds, vdims='Count') self.assertEqual(img, expected)
def test_aggregate_dt_xaxis_constant_yaxis(self): df = pd.DataFrame({'y': np.ones(100)}, index=pd.date_range('1980-01-01', periods=100, freq='1T')) img = rasterize(Curve(df), dynamic=False) xs = np.array(['1980-01-01T00:16:30.000000', '1980-01-01T00:49:30.000000', '1980-01-01T01:22:30.000000'], dtype='datetime64[us]') ys = np.array([]) bounds = (np.datetime64('1980-01-01T00:00:00.000000'), 1.0, np.datetime64('1980-01-01T01:39:00.000000'), 1.0) expected = Image((xs, ys, np.empty((0, 3))), ['index', 'y'], 'Count', xdensity=1, ydensity=1, bounds=bounds) self.assertEqual(img, expected)
def test_curve_heterogeneous_datetime_types_with_pd_overlay(self): if not pd: raise SkipTest("Pandas not available") dates_pd = pd.date_range('2016-01-04', '2016-01-13', freq='D') dates64 = [np.datetime64(dt.datetime(2016,1,i)) for i in range(1, 11)] dates = [dt.datetime(2016,1,i) for i in range(2, 12)] curve_dt64 = Curve((dates64, np.random.rand(10))) curve_dt = Curve((dates, np.random.rand(10))) curve_pd = Curve((dates_pd, np.random.rand(10))) plot = bokeh_renderer.get_plot(curve_dt*curve_dt64*curve_pd) self.assertEqual(plot.handles['x_range'].start, np.datetime64(dt.datetime(2016, 1, 1))) self.assertEqual(plot.handles['x_range'].end, np.datetime64(dt.datetime(2016, 1, 13)))
def test_curve_overlay_datetime_hover(self): obj = NdOverlay( { i: Curve((list(pd.date_range('2016-01-01', '2016-01-31')), range(31))) for i in range(5) }, kdims=['Test']) opts = {'Curve': {'tools': ['hover']}} obj = obj(plot=opts) self._test_hover_info(obj, [('Test', '@{Test}'), ('x', '@{x_dt_strings}'), ('y', '@{y}')])
def test_aggregate_curve_datetimes_microsecond_timebase(self): dates = pd.date_range(start="2016-01-01", end="2016-01-03", freq='1D') xstart = np.datetime64('2015-12-31T23:59:59.723518000', 'us') xend = np.datetime64('2016-01-03T00:00:00.276482000', 'us') curve = Curve((dates, [1, 2, 3])) img = aggregate(curve, width=2, height=2, x_range=(xstart, xend), dynamic=False) bounds = (np.datetime64('2015-12-31T23:59:59.723518'), 1.0, np.datetime64('2016-01-03T00:00:00.276482'), 3.0) dates = [np.datetime64('2016-01-01T11:59:59.861759000',), np.datetime64('2016-01-02T12:00:00.138241000')] expected = Image((dates, [1.5, 2.5], [[1, 0], [0, 2]]), datatype=['xarray'], bounds=bounds, vdims='Count') self.assertEqual(img, expected)
def test_histogram_operation_pd_period(self): dates = pd.date_range('2017-01-01', '2017-01-04', freq='D').to_period('D') op_hist = histogram(Dataset(dates, 'Date'), num_bins=4) hist_data = { 'Date': np.array([ '2017-01-01T00:00:00.000000', '2017-01-01T18:00:00.000000', '2017-01-02T12:00:00.000000', '2017-01-03T06:00:00.000000', '2017-01-04T00:00:00.000000'], dtype='datetime64[us]'), 'Date_frequency': np.array([ 3.85802469e-18, 3.85802469e-18, 3.85802469e-18, 3.85802469e-18]) } hist = Histogram(hist_data, kdims='Date', vdims=('Date_frequency', 'Frequency')) self.assertEqual(op_hist, hist)
def test_histogram_operation_pd_period(self): dates = pd.date_range('2017-01-01', '2017-01-04', freq='D').to_period('D') op_hist = histogram(Dataset(dates, 'Date'), num_bins=4, normed=True) hist_data = { 'Date': np.array([ '2017-01-01T00:00:00.000000', '2017-01-01T18:00:00.000000', '2017-01-02T12:00:00.000000', '2017-01-03T06:00:00.000000', '2017-01-04T00:00:00.000000'], dtype='datetime64[us]'), 'Date_frequency': np.array([ 3.85802469e-18, 3.85802469e-18, 3.85802469e-18, 3.85802469e-18]) } hist = Histogram(hist_data, kdims='Date', vdims=('Date_frequency', 'Frequency')) self.assertEqual(op_hist, hist)
def test_aggregate_curve_datetimes_dask(self): df = pd.DataFrame( data=np.arange(1000), columns=['a'], index=pd.date_range('2019-01-01', freq='1T', periods=1000), ) ddf = dd.from_pandas(df, npartitions=4) curve = Curve(ddf, kdims=['index'], vdims=['a']) img = aggregate(curve, width=2, height=3, dynamic=False) bounds = (np.datetime64('2019-01-01T00:00:00.000000'), 0.0, np.datetime64('2019-01-01T16:39:00.000000'), 999.0) dates = [np.datetime64('2019-01-01T04:09:45.000000000'), np.datetime64('2019-01-01T12:29:15.000000000')] expected = Image((dates, [166.5, 499.5, 832.5], [[332, 0], [167, 166], [0, 334]]), ['index', 'a'], 'Count', datatype=['xarray'], bounds=bounds) self.assertEqual(img, expected)
def test_aggregate_curve_datetimes_dask(self): df = pd.DataFrame( data=np.arange(1000), columns=['a'], index=pd.date_range('2019-01-01', freq='1T', periods=1000), ) ddf = dd.from_pandas(df, npartitions=4) curve = Curve(ddf, kdims=['index'], vdims=['a']) img = aggregate(curve, width=2, height=3, dynamic=False) bounds = (np.datetime64('2019-01-01T00:00:00.000000'), 0.0, np.datetime64('2019-01-01T16:39:00.000000'), 999.0) dates = [np.datetime64('2019-01-01T04:09:45.000000000'), np.datetime64('2019-01-01T12:29:15.000000000')] expected = Image((dates, [166.5, 499.5, 832.5], [[333, 0], [167, 166], [0, 334]]), ['index', 'a'], 'Count', datatype=['xarray'], bounds=bounds) self.assertEqual(img, expected)
def test_aggregate_ndoverlay_count_cat_datetimes_microsecond_timebase(self): dates = pd.date_range(start="2016-01-01", end="2016-01-03", freq='1D') xstart = np.datetime64('2015-12-31T23:59:59.723518000', 'us') xend = np.datetime64('2016-01-03T00:00:00.276482000', 'us') curve = Curve((dates, [1, 2, 3])) curve2 = Curve((dates, [3, 2, 1])) ndoverlay = NdOverlay({0: curve, 1: curve2}, 'Cat') imgs = aggregate(ndoverlay, aggregator=ds.count_cat('Cat'), width=2, height=2, x_range=(xstart, xend), dynamic=False) bounds = (np.datetime64('2015-12-31T23:59:59.723518'), 1.0, np.datetime64('2016-01-03T00:00:00.276482'), 3.0) dates = [np.datetime64('2016-01-01T11:59:59.861759000',), np.datetime64('2016-01-02T12:00:00.138241000')] expected = Image((dates, [1.5, 2.5], [[1, 0], [0, 2]]), datatype=['xarray'], bounds=bounds, vdims='Count') expected2 = Image((dates, [1.5, 2.5], [[0, 1], [1, 1]]), datatype=['xarray'], bounds=bounds, vdims='Count') self.assertEqual(imgs[0], expected) self.assertEqual(imgs[1], expected2)
def test_curve_pandas_timestamps(self): dates = pd.date_range('2016-01-01', '2016-01-10', freq='D') curve = Curve((dates, np.random.rand(10))) plot = mpl_renderer.get_plot(curve) self.assertEqual(plot.handles['axis'].get_xlim(), (16801.0, 16810.0))
def test_curve_pandas_timestamps(self): dates = pd.date_range('2016-01-01', '2016-01-10', freq='D') curve = Curve((dates, np.random.rand(10))) plot = mpl_renderer.get_plot(curve) self.assertEqual(plot.handles['axis'].get_xlim(), (735964.0, 735973.0))