From 4ccdfd28600d3259df6e46b55ff53329afd7cc51 Mon Sep 17 00:00:00 2001 From: Jianfeng Mao <4297243+jmao-denver@users.noreply.github.com> Date: Thu, 10 Aug 2023 12:07:45 -0600 Subject: [PATCH] Wrap hasColumns (#4305) --- py/server/deephaven/table.py | 13 +++++++++++++ py/server/tests/test_table.py | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/py/server/deephaven/table.py b/py/server/deephaven/table.py index 3b4e6318482..7cb866296ae 100644 --- a/py/server/deephaven/table.py +++ b/py/server/deephaven/table.py @@ -570,6 +570,19 @@ def meta_table(self) -> Table: def j_object(self) -> jpy.JType: return self.j_table + def has_columns(self, cols: Union[str, Sequence[str]]): + """Whether this table contains a column for each of the provided names, return False if any of the columns is + not in the table. + + Args: + cols (Union[str, Sequence[str]]): the column name(s) + + Returns: + bool + """ + cols = to_sequence(cols) + return self.j_table.hasColumns(cols) + def attributes(self) -> Dict[str, Any]: """Returns all the attributes defined on the table.""" j_map = jpy.cast(self.j_table, _JAttributeMap).getAttributes() diff --git a/py/server/tests/test_table.py b/py/server/tests/test_table.py index 3d6da431ecb..27cb7e9e1f7 100644 --- a/py/server/tests/test_table.py +++ b/py/server/tests/test_table.py @@ -15,7 +15,6 @@ from deephaven.pandas import to_pandas from deephaven.table import Table, SearchDisplayMode from deephaven.time import epoch_nanos_to_instant -from tests.testbase import BaseTestCase from tests.testbase import BaseTestCase, table_equals @@ -1049,6 +1048,13 @@ def test_agg_with_options(self): with self.assertRaises(DHError): agg = unique(cols=["ua = a", "ub = b"], include_nulls=True, non_unique_sentinel=None) + def test_has_columns(self): + t = empty_table(1).update(["A=i", "B=i", "C=i"]) + self.assertTrue(t.has_columns("B")) + self.assertTrue(t.has_columns(["A", "C"])) + self.assertFalse(t.has_columns("D")) + self.assertFalse(t.has_columns(["D", "C"])) + if __name__ == "__main__": unittest.main()