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)
Esempio n. 2
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
Esempio 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)
Esempio 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]),
        }
Esempio 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)
Esempio n. 6
0
    def test_array_column(self):
        strings = ["Str1", "Str1", "Str2", "Str2"]
        doubles = [1.0, 2.0, 4.0, 8.0]
        test_table = new_table([
            string_col("StringColumn", strings),
            double_col("Decimals", doubles)
        ])

        test_table = test_table.group_by(["StringColumn"])

        self.assertIsNone(test_table.columns[0].component_type)
        self.assertEqual(test_table.columns[1].component_type, dtypes.double)
Esempio n. 7
0
    def test_vector_column(self):
        strings = ["Str1", "Str1", "Str2", "Str2", "Str2"]
        doubles = [1.0, 2.0, 4.0, 8.0, 16.0]
        test_table = new_table(
            [string_col("String", strings),
             double_col("Doubles", doubles)])

        test_table = test_table.group_by(["String"])
        df = to_pandas(test_table, cols=["String", "Doubles"])
        self.assertEqual(df['String'].dtype, np.object_)
        self.assertEqual(df['Doubles'].dtype, np.object_)

        double_series = df['Doubles']
        self.assertEqual([1.0, 2.0], list(double_series[0].toArray()))
        self.assertEqual([4.0, 8.0, 16.0], list(double_series[1].toArray()))
Esempio 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")])