Skip to content

Commit

Permalink
Wrap hasColumns (deephaven#4305)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver authored Aug 10, 2023
1 parent 57b429e commit 4ccdfd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions py/server/deephaven/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion py/server/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()

0 comments on commit 4ccdfd2

Please sign in to comment.