def test_points_histogram_not_normed(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, normed=False)

        hist = Histogram(([0, 3, 6, 9], [3, 3, 4]),
                         vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
    def test_points_histogram_explicit_bins(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, bins=[0, 1, 3], normed=False)

        hist = Histogram(([0, 1, 3], [1, 3]),
                         vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 3
0
    def test_points_histogram_bin_range(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, bin_range=(0, 3))

        hist = Histogram(([0.25, 0.25, 0.5], [0., 1., 2., 3.]),
                         vdims=('x_frequency', 'Frequency'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 4
0
    def test_points_histogram(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3)

        hist = Histogram(([0.1, 0.1, 0.133333], [0, 3, 6, 9]),
                         vdims=('x_frequency', 'Frequency'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 5
0
    def test_points_histogram_not_normed(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, normed=False)

        hist = Histogram(([3, 3, 4], [0, 3, 6, 9]),
                         vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 6
0
    def test_points_histogram_cumulative(self):
        arr = np.arange(4)
        points = Points(arr)
        op_hist = histogram(points, cumulative=True, num_bins=3, normed=False)

        hist = Histogram(([0, 1, 2, 3], [1, 2, 4]), vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 7
0
    def test_points_histogram_explicit_bins(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, bins=[0, 1, 3], normed=False)

        hist = Histogram(([0, 1, 3], [1, 3]),
                         vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 8
0
    def test_points_histogram_bin_range(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, bin_range=(0, 3))

        hist = Histogram(([0.25, 0.25, 0.5], [0., 1., 2., 3.]),
                         vdims=('x_frequency', 'Frequency'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 9
0
    def test_points_histogram(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3)

        hist = Histogram(([0.1, 0.1, 0.133333], [0, 3, 6, 9]),
                         vdims=('x_frequency', 'Frequency'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 10
0
    def test_points_histogram_cumulative(self):
        arr = np.arange(4)
        points = Points(arr)
        op_hist = histogram(points, cumulative=True, num_bins=3, normed=False)

        hist = Histogram(([0, 1, 2, 3], [1, 2, 4]),
                         vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 11
0
 def test_points_histogram_mean_weighted(self):
     points = Points([float(i) for i in range(10)])
     op_hist = histogram(points,
                         num_bins=3,
                         weight_dimension='y',
                         mean_weighted=True)
     hist = Histogram(([1., 4., 7.5], [0, 3, 6, 9]), vdims=['y'])
     self.assertEqual(op_hist, hist)
    def test_dataset_cumulative_histogram_dask(self):
        import dask.array as da
        ds = Dataset((da.from_array(np.array(range(10), dtype='f'), chunks=(3)),),
                     ['x'], datatype=['dask'])
        op_hist = histogram(ds, num_bins=3, cumulative=True, normed=True)

        hist = Histogram(([0, 3, 6, 9], [0.3, 0.6, 1]),
                         vdims=('x_frequency', 'Frequency'))
        self.assertIsInstance(op_hist.data['x_frequency'], da.Array)
        self.assertEqual(op_hist, hist)
    def test_dataset_weighted_histogram_dask(self):
        import dask.array as da
        ds = Dataset((da.from_array(np.array(range(10), dtype='f'), chunks=3),
                      da.from_array([i/10. for i in range(10)], chunks=3)),
                     ['x', 'y'], datatype=['dask'])
        op_hist = histogram(ds, weight_dimension='y', num_bins=3, normed=True)

        hist = Histogram(([0, 3, 6, 9], [0.022222, 0.088889, 0.222222]),
                         vdims='y')
        self.assertIsInstance(op_hist.data['y'], da.Array)
        self.assertEqual(op_hist, hist)
Ejemplo n.º 14
0
    def test_points_histogram_not_normed(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, normed=False)

        # Make sure that the name and label are as desired
        op_freq_dim = op_hist.get_dimension('x_frequency')
        self.assertEqual(op_freq_dim.label, 'x Frequency')

        # Because the operation labels are now different from the
        #  default Element label, change back before comparing.
        op_hist = op_hist.redim(x_frequency='Frequency')
        hist = Histogram(([3, 3, 4], [0, 3, 6, 9]))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 15
0
    def test_points_histogram_bin_range(self):
        points = Points([float(i) for i in range(10)])
        op_hist = histogram(points, num_bins=3, bin_range=(0, 3))

        # Make sure that the name and label are as desired
        op_freq_dim = op_hist.get_dimension('x_frequency')
        self.assertEqual(op_freq_dim.label, 'x Frequency')

        # Because the operation labels are now different from the 
        #  default Element label, change back before comparing.
        op_hist = op_hist.redim(x_frequency='Frequency')
        hist = Histogram(([0.25, 0.25, 0.5], [0., 1., 2., 3.]))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 16
0
    def test_points_histogram_cumulative(self):
        arr = np.arange(4)
        points = Points(arr)
        op_hist = histogram(points, cumulative=True, num_bins=3, normed=False)

        # Make sure that the name and label are as desired
        op_freq_dim = op_hist.get_dimension('x_frequency')
        self.assertEqual(op_freq_dim.label, 'x Frequency')

        # Because the operation labels are now different from the
        #  default Element label, change back before comparing.
        op_hist = op_hist.redim(x_frequency='Frequency')
        hist = Histogram(([0, 1, 2, 3], [1, 2, 4]))
        self.assertEqual(op_hist, hist)
Ejemplo n.º 17
0
 def test_histogram_operation_datetime64(self):
     dates = np.array([dt.datetime(2017, 1, i) for i in range(1, 5)]).astype('M')
     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)
Ejemplo n.º 18
0
 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_histogram_operation_datetime64(self):
     dates = np.array([dt.datetime(2017, 1, i) for i in range(1, 5)]).astype('M')
     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)
Ejemplo n.º 21
0
    def test_histogram_operation_kwargs(self):
        points = Points([float(j) for i in range(10) for j in [i] * (2 * i)])
        op_hist = histogram(
            points,
            dimension='y',
            normed=False,
            num_bins=10,
            bin_range=[0, 10],
        )

        hist = Histogram(
            ([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0
              ], [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]),
            vdims=('y_count', 'Count'),
            kdims='y')

        # Check histogram
        self.assertEqual(op_hist, hist)

        # Check operation kwargs for histogram generated with operation
        self.assertEqual(
            op_hist._operation_kwargs, {
                'dimension': 'y',
                'normed': False,
                'dynamic': False,
                'bins':
                [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
            })

        # Test that operation_kwargs is preserved through clone
        self.assertEqual(
            op_hist.clone()._operation_kwargs, {
                'dimension': 'y',
                'normed': False,
                'dynamic': False,
                'bins':
                [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
            })

        # Check that operation kwargs is None for histogram generated directly
        # from the Histogram constructor
        self.assertIsNone(hist._operation_kwargs)
Ejemplo n.º 22
0
 def test_points_histogram_weighted(self):
     points = Points([float(i) for i in range(10)])
     op_hist = histogram(points, num_bins=3, weight_dimension='y')
     hist = Histogram(([0.022222, 0.088889, 0.222222], [0, 3, 6, 9]),
                      vdims=['y'])
     self.assertEqual(op_hist, hist)
Ejemplo n.º 23
0
 def test_points_histogram_weighted(self):
     points = Points([float(i) for i in range(10)])
     op_hist = histogram(points, num_bins=3, weight_dimension='y')
     hist = Histogram(([0.022222, 0.088889, 0.222222], [0, 3, 6, 9]), vdims=['y'])
     self.assertEqual(op_hist, hist)
Ejemplo n.º 24
0
 def test_points_histogram_mean_weighted(self):
     points = Points([float(i) for i in range(10)])
     op_hist = histogram(points, num_bins=3, weight_dimension='y', mean_weighted=True)
     hist = Histogram(([1.,  4., 7.5], [0, 3, 6, 9]), vdims=['y'])
     self.assertEqual(op_hist, hist)
    def test_dataset_histogram_empty_explicit_bins(self):
        ds = Dataset([np.nan, np.nan], ['x'])
        op_hist = histogram(ds, bins=[0, 1, 2])

        hist = Histogram(([0, 1, 2], [0, 0]), vdims=('x_count', 'Count'))
        self.assertEqual(op_hist, hist)