def test_adapt_internal(self):
     b1 = binnings.FixedWidthBinning(bin_width=10,
                                     bin_count=3,
                                     min=0,
                                     adaptive=True)
     b2 = binnings.FixedWidthBinning(bin_width=10,
                                     bin_count=1,
                                     min=10,
                                     adaptive=True)
     m1, m2 = b1.adapt(b2)
     assert m1 is None
     assert tuple(m2) == ((0, 1), )
 def test_adapt_intersection2(self):
     b = binnings.FixedWidthBinning(bin_width=10,
                                    bin_count=3,
                                    min=0,
                                    adaptive=True)
     b6 = binnings.FixedWidthBinning(bin_width=10,
                                     bin_count=3,
                                     min=10,
                                     adaptive=True)
     m1, m2 = b6.adapt(b)
     assert tuple(m1) == ((0, 1), (1, 2), (2, 3))
     assert tuple(m2) == ((0, 0), (1, 1), (2, 2))
     assert b6.bin_count == 4
 def test_adapt_right(self):
     b = binnings.FixedWidthBinning(bin_width=10,
                                    bin_count=3,
                                    min=0,
                                    adaptive=True)
     b4 = binnings.FixedWidthBinning(bin_width=10,
                                     bin_count=2,
                                     min=-30,
                                     adaptive=True)
     m1, m2 = b4.adapt(b)
     assert tuple(m1) == ((0, 0), (1, 1))
     assert tuple(m2) == ((0, 3), (1, 4), (2, 5))
     assert b4.bin_count == 6
 def test_adapt_left(self):
     b = binnings.FixedWidthBinning(bin_width=10,
                                    bin_count=3,
                                    min=0,
                                    adaptive=True)
     b3 = binnings.FixedWidthBinning(bin_width=10,
                                     bin_count=2,
                                     min=50,
                                     adaptive=True)
     m1, m2 = b3.adapt(b)
     assert tuple(m1) == ((0, 5), (1, 6))
     assert tuple(m2) == ((0, 0), (1, 1), (2, 2))
     assert b3.bin_count == 7
 def test_adapt_extension(self):
     b = binnings.FixedWidthBinning(bin_width=10,
                                    bin_count=3,
                                    min=0,
                                    adaptive=True)
     b2 = binnings.FixedWidthBinning(bin_width=10,
                                     bin_count=2,
                                     min=0,
                                     adaptive=True)
     m1, m2 = b2.adapt(b)
     assert tuple(m1) == ((0, 0), (1, 1))
     assert m2 is None
     assert np.array_equal(b2.numpy_bins, [0, 10, 20, 30])
     assert b2.bin_count == 3
    def test_adapt_wrong(self):
        b1 = binnings.FixedWidthBinning(bin_width=10,
                                        bin_count=2,
                                        min=0,
                                        adaptive=True)
        b2 = binnings.FixedWidthBinning(bin_width=10,
                                        bin_count=2,
                                        min=1,
                                        adaptive=True)
        with self.assertRaises(RuntimeError):
            b1.adapt(b2)
        with self.assertRaises(RuntimeError):
            b2.adapt(b1)

        b3 = binnings.FixedWidthBinning(bin_width=5,
                                        bin_count=6,
                                        min=0,
                                        adaptive=True)
        with self.assertRaises(RuntimeError):
            b1.adapt(b3)
        with self.assertRaises(RuntimeError):
            b3.adapt(b1)