def test_get_constituent(self):
        keys = [917, 167]
        self.assertIsNotNone(self.partitioned_table.get_constituent(keys))

        from deephaven.column import string_col, int_col, double_col

        houses = new_table([
            string_col("HomeType", [
                "Colonial", "Contemporary", "Contemporary", "Condo",
                "Colonial", "Apartment"
            ]),
            int_col("HouseNumber", [1, 3, 4, 15, 4, 9]),
            string_col("StreetName", [
                "Test Drive", "Test Drive", "Test Drive", "Deephaven Road",
                "Community Circle", "Community Circle"
            ]),
            int_col("SquareFeet", [2251, 1914, 4266, 1280, 3433, 981]),
            int_col("Price",
                    [450000, 400000, 1250000, 300000, 600000, 275000]),
            double_col("LotSizeAcres", [0.41, 0.26, 1.88, 0.11, 0.95, 0.10])
        ])

        houses_by_type = houses.partition_by("HomeType")
        colonial_homes = houses_by_type.get_constituent("Colonial")
        self.assertIsNotNone(colonial_homes)
Ejemplo n.º 2
0
    def test_historical_table_replayer(self):
        dt1 = to_datetime("2000-01-01T00:00:01 NY")
        dt2 = to_datetime("2000-01-01T00:00:02 NY")
        dt3 = to_datetime("2000-01-01T00:00:04 NY")

        hist_table = new_table([
            datetime_col("DateTime", [dt1, dt2, dt3]),
            int_col("Number", [1, 3, 6])
        ])

        hist_table2 = new_table([
            datetime_col("DateTime", [dt1, dt2, dt3]),
            int_col("Number", [1, 3, 6])
        ])

        start_time = to_datetime("2000-01-01T00:00:00 NY")
        end_time = to_datetime("2000-01-01T00:00:05 NY")

        replayer = TableReplayer(start_time, end_time)
        replay_table = replayer.add_table(hist_table, "DateTime")
        replay_table2 = replayer.add_table(hist_table2, "DateTime")
        self.assert_table_equals(replay_table, replay_table2)

        replayer.start()
        self.assertTrue(replay_table.is_refreshing)
        self.assertTrue(replay_table2.is_refreshing)
        self.wait_ticking_table_update(replay_table, row_count=3, timeout=60)
        self.wait_ticking_table_update(replay_table2, row_count=3, timeout=60)
        self.assert_table_equals(replay_table, replay_table2)
        replayer.shutdown()

        with self.subTest("replayer can't be reused after shutdown."):
            with self.assertRaises(DHError) as cm:
                replayer.add_table(hist_table, "DateTime")
            self.assertIn("RuntimeError", cm.exception.root_cause)

        with self.subTest("replayer can't be restarted after shutdown."):
            with self.assertRaises(DHError):
                replayer.start()

        with self.subTest("Add table after replayer is restarted."):
            replayer = TableReplayer(start_time, end_time)
            replayer.start()
            replay_table = replayer.add_table(hist_table, "DateTime")
            self.assertTrue(replay_table.is_refreshing)
            self.wait_ticking_table_update(replay_table,
                                           row_count=3,
                                           timeout=60)
            replayer.shutdown()
Ejemplo n.º 3
0
 def setUp(self):
     j_array_list1 = j_array_list([1, -1])
     j_array_list2 = j_array_list([2, -2])
     input_cols = [
         bool_col(name="Boolean", data=[True, False]),
         byte_col(name="Byte", data=(1, -1)),
         char_col(name="Char", data='-1'),
         short_col(name="Short", data=[1, -1]),
         int_col(name="Int_", data=[1, -1]),
         long_col(name="Long_", data=[1, NULL_LONG]),
         long_col(name="NPLong", data=np.array([1, -1], dtype=np.int8)),
         float_col(name="Float_", data=[1.01, -1.01]),
         double_col(name="Double_", data=[1.01, -1.01]),
         string_col(name="String", data=["foo", "bar"]),
         datetime_col(name="Datetime",
                      data=[dtypes.DateTime(1),
                            dtypes.DateTime(-1)]),
         pyobj_col(name="PyObj",
                   data=[CustomClass(1, "1"),
                         CustomClass(-1, "-1")]),
         pyobj_col(name="PyObj1", data=[[1, 2, 3],
                                        CustomClass(-1, "-1")]),
         pyobj_col(name="PyObj2", data=[False, 'False']),
         jobj_col(name="JObj", data=[j_array_list1, j_array_list2]),
     ]
     self.test_table = new_table(cols=input_cols)
Ejemplo n.º 4
0
    def setUp(self):
        j_array_list1 = j_array_list([1, -1])
        j_array_list2 = j_array_list([2, -2])
        input_cols = [
            bool_col(name="Boolean", data=[True, False]),
            byte_col(name="Byte", data=(1, -1)),
            char_col(name="Char", data='-1'),
            short_col(name="Short", data=[1, -1]),
            int_col(name="Int", data=[1, -1]),
            long_col(name="Long", data=[1, NULL_LONG]),
            long_col(name="NPLong", data=np.array([1, -1], dtype=np.int8)),
            float_col(name="Float", data=[1.01, -1.01]),
            double_col(name="Double", data=[1.01, -1.01]),
            string_col(name="String", data=["foo", "bar"]),
            datetime_col(name="Datetime",
                         data=[dtypes.DateTime(1),
                               dtypes.DateTime(-1)]),
            pyobj_col(name="PyObj",
                      data=[CustomClass(1, "1"),
                            CustomClass(-1, "-1")]),
            pyobj_col(name="PyObj1", data=[[1, 2, 3],
                                           CustomClass(-1, "-1")]),
            pyobj_col(name="PyObj2", data=[False, 'False']),
            jobj_col(name="JObj", data=[j_array_list1, j_array_list2]),
        ]
        self.test_table = new_table(cols=input_cols)

        self.np_array_dict = {
            'Boolean':
            np.array([True, False]),
            'Byte':
            np.array([1, -1], dtype=np.int8),
            'Char':
            np.array('-1', dtype=np.int16),
            'Short':
            np.array([1, -1], dtype=np.int16),
            'Int':
            np.array([1, -1], dtype=np.int32),
            'Long':
            np.array([1, NULL_LONG], dtype=np.int64),
            "NPLong":
            np.array([1, -1], dtype=np.int8),
            "Float":
            np.array([1.01, -1.01], dtype=np.float32),
            "Double":
            np.array([1.01, -1.01]),
            "String":
            np.array(["foo", "bar"], dtype=np.string_),
            "Datetime":
            np.array([1, -1], dtype=np.dtype("datetime64[ns]")),
            "PyObj":
            np.array([CustomClass(1, "1"),
                      CustomClass(-1, "-1")]),
            "PyObj1":
            np.array([[1, 2, 3], CustomClass(-1, "-1")], dtype=np.object_),
            "PyObj2":
            np.array([False, 'False'], dtype=np.object_),
            "JObj":
            np.array([j_array_list1, j_array_list2]),
        }
Ejemplo n.º 5
0
    def test_new_table(self):
        jobj1 = JArrayList()
        jobj1.add(1)
        jobj1.add(-1)
        jobj2 = JArrayList()
        jobj2.add(2)
        jobj2.add(-2)
        cols = [
            bool_col(name="Boolean", data=[True, False]),
            byte_col(name="Byte", data=(1, -1)),
            char_col(name="Char", data='-1'),
            short_col(name="Short", data=[1, -1]),
            int_col(name="Int", data=[1, -1]),
            long_col(name="Long", data=[1, -1]),
            long_col(name="NPLong", data=np.array([1, -1], dtype=np.int8)),
            float_col(name="Float", data=[1.01, -1.01]),
            double_col(name="Double", data=[1.01, -1.01]),
            string_col(name="String", data=["foo", "bar"]),
            datetime_col(name="Datetime",
                         data=[dtypes.DateTime(1),
                               dtypes.DateTime(-1)]),
            pyobj_col(name="PyObj",
                      data=[CustomClass(1, "1"),
                            CustomClass(-1, "-1")]),
            pyobj_col(name="PyObj1", data=[[1, 2, 3],
                                           CustomClass(-1, "-1")]),
            pyobj_col(name="PyObj2", data=[False, 'False']),
            jobj_col(name="JObj", data=[jobj1, jobj2]),
        ]

        t = new_table(cols=cols)
        self.assertEqual(t.size, 2)
Ejemplo n.º 6
0
def table_helper():
    columns = [
        string_col('Symbol', ['MSFT', 'GOOG', 'AAPL', 'AAPL']),
        string_col('Side', ['B', 'B', 'S', 'B']),
        int_col('Qty', [200, 100, 300, 50]),
        double_col('Price', [210.0, 310.5, 411.0, 411.5])
    ]
    t = new_table(cols=columns)
    return t
Ejemplo n.º 7
0
 def test_round_trip_with_nulls(self):
     # Note that no two-way conversion for those types
     # j_array_list = dtypes.ArrayList([1, -1])
     # bool_col(name="Boolean", data=[True, None])]
     # string_col(name="String", data=["foo", None]),
     # jobj_col(name="JObj", data=[j_array_list, None]),
     input_cols = [
         byte_col(name="Byte", data=(1, NULL_BYTE)),
         char_col(name="Char", data='-1'),
         short_col(name="Short", data=[1, NULL_SHORT]),
         int_col(name="Int_", data=[1, NULL_INT]),
         long_col(name="Long_", data=[1, NULL_LONG]),
         float_col(name="Float_", data=[1.01, np.nan]),
         double_col(name="Double_", data=[1.01, np.nan]),
         datetime_col(name="Datetime", data=[dtypes.DateTime(1), None]),
         pyobj_col(name="PyObj", data=[CustomClass(1, "1"), None]),
     ]
     test_table = new_table(cols=input_cols)
     df = to_pandas(test_table)
     self.assertEqual(len(df.columns), len(test_table.columns))
     self.assertEqual(df.size, 2 * len(test_table.columns))
     test_table2 = to_table(df)
     self.assert_table_equals(test_table2, test_table)
Ejemplo n.º 8
0
    def test_column_error(self):
        jobj = j_array_list([1, -1])
        with self.assertRaises(DHError) as cm:
            bool_input_col = bool_col(name="Boolean", data=[True, 'abc'])

        self.assertNotIn("bool_input_col", dir())

        with self.assertRaises(DHError) as cm:
            _ = byte_col(name="Byte", data=[1, 'abc'])

        with self.assertRaises(DHError) as cm:
            _ = char_col(name="Char", data=[jobj])

        with self.assertRaises(DHError) as cm:
            _ = short_col(name="Short", data=[1, 'abc'])

        with self.assertRaises(DHError) as cm:
            _ = int_col(name="Int", data=[1, [1, 2]])

        with self.assertRaises(DHError) as cm:
            _ = long_col(name="Long", data=[1, float('inf')])

        with self.assertRaises(DHError) as cm:
            _ = float_col(name="Float", data=[1.01, 'NaN'])

        with self.assertRaises(DHError) as cm:
            _ = double_col(name="Double", data=[1.01, jobj])

        with self.assertRaises(DHError) as cm:
            _ = string_col(name="String", data=[1, -1.01])

        with self.assertRaises(DHError) as cm:
            _ = datetime_col(name="Datetime",
                             data=[dtypes.DateTime(round(time.time())), False])

        with self.assertRaises(DHError) as cm:
            _ = jobj_col(name="JObj", data=[jobj, CustomClass(-1, "-1")])