diff --git a/py/client/pydeephaven/ticket.py b/py/client/pydeephaven/ticket.py index d0a38753b3b..9f425aa35cb 100644 --- a/py/client/pydeephaven/ticket.py +++ b/py/client/pydeephaven/ticket.py @@ -145,11 +145,11 @@ def __init__(self, ticket_bytes: bytes): raise DHError('ApplicationTicket: ticket is None') elif not ticket_bytes.startswith(b'a/'): raise DHError(f'ApplicationTicket: ticket {ticket_bytes} is not an application ticket') - elif len(ticket_bytes.split(b'/')) != 3: + elif len(ticket_bytes.split(b'/')) != 4: raise DHError(f'ApplicationTicket: ticket {ticket_bytes} is not in the correct format') self.app_id = ticket_bytes.split(b'/')[1].decode(encoding='ascii') - self.field = ticket_bytes.split(b'/')[2].decode(encoding='ascii') + self.field = ticket_bytes.split(b'/')[3].decode(encoding='ascii') super().__init__(ticket_bytes) @@ -169,7 +169,7 @@ def app_ticket(cls, app_id: str, field: str) -> ApplicationTicket: if not field: raise DHError('app_ticket: field must be a non-empty string') - return cls(ticket_bytes=f'a/{app_id}/{field}'.encode(encoding='ascii')) + return cls(ticket_bytes=f'a/{app_id}/f/{field}'.encode(encoding='ascii')) def _ticket_from_proto(ticket: ticket_pb2.Ticket) -> Ticket: diff --git a/py/client/tests/test_plugin_client.py b/py/client/tests/test_plugin_client.py index b0e3a565e6e..ae8b3041a73 100644 --- a/py/client/tests/test_plugin_client.py +++ b/py/client/tests/test_plugin_client.py @@ -4,7 +4,7 @@ import unittest from pydeephaven.session import Session -from pydeephaven.ticket import SharedTicket, ServerObject +from pydeephaven.ticket import SharedTicket, ServerObject, ScopeTicket from tests.testbase import BaseTestCase @@ -14,9 +14,12 @@ def setUp(self) -> None: server_script = ''' from deephaven.plot.figure import Figure from deephaven import empty_table +import deephaven.pandas as dhpd source = empty_table(20).update(["Letter = (i % 2 == 0) ? `A` : `B`", "X = 0.1 * i", "Y = randomDouble(0.0, 5.0)"]) +df = dhpd.to_pandas(source) + plot = Figure().plot_xy(series_name="Random numbers", t=source, x="X", y="Y").show() source2 = empty_table(20).update(["Letter = (i % 2 == 0) ? `A` : `B`", "X = 0.1 * i", "Y = randomDouble(0.0, 5.0)"]) @@ -36,8 +39,10 @@ def test_create(self): self.assertGreater(len(refs), 0) ref = refs[0] self.assertEqual(ref.type, "Table") + plugin_client.close() - def test_publish_fetch(self): + @unittest.skip("need to wait for https://github.com/deephaven/deephaven-core/issues/5996") + def test_publish_fetch_figure(self): plugin_client = self.session.plugin_client(self.session.exportable_objects["plot3"]) self.assertIsNotNone(plugin_client) @@ -63,7 +68,6 @@ def test_publish_fetch(self): sub_session.close() with self.subTest("Fetchable in the Plugin object"): - self.skipTest("need to wait for https://github.com/deephaven/deephaven-core/issues/5996") payload, refs = next(plugin_client.resp_stream) self.assertGreater(len(payload), 0) self.assertGreater(len(refs), 0) @@ -85,7 +89,6 @@ def test_publish_fetch(self): sub_session.close() with self.subTest("released Plugin object"): - self.skipTest("need to wait for https://github.com/deephaven/deephaven-core/issues/5996") sub_session = Session() server_obj = ServerObject(type="Figure", ticket=shared_ticket) sub_plugin_client = sub_session.plugin_client(server_obj) @@ -96,6 +99,52 @@ def test_publish_fetch(self): plugin_client.close() + @unittest.skip("need to wait for https://github.com/deephaven/deephaven-core/issues/5996") + def test_publish_fetch_pandas(self): + plugin_client = self.session.plugin_client(self.session.exportable_objects["df"]) + self.assertIsNotNone(plugin_client) + + # First fetch the Plugin object, then publish it + export_plugin_client = self.session.fetch(plugin_client) + shared_ticket = SharedTicket.random_ticket() + self.session.publish(export_plugin_client, shared_ticket) + + # Another session to use the shared Plugin object + sub_session = Session() + server_obj = ServerObject(type="pandas.DataFrame", ticket=shared_ticket) + sub_plugin_client = sub_session.plugin_client(server_obj) + payload, refs = next(sub_plugin_client.resp_stream) + self.assertEqual(len(payload), 0) + self.assertEqual(len(refs), 1) + ref = refs[0] + self.assertEqual(ref.type, "Table") + fetched = ref.fetch() + self.assertIsNotNone(fetched) + self.assertEqual(fetched.size, 20) + sub_plugin_client.close() + sub_session.close() + + # continue with source plugin client + payload, refs = next(plugin_client.resp_stream) + self.assertEqual(len(payload), 0) + self.assertEqual(len(refs), 1) + ref = refs[0] + self.assertEqual(ref.type, "Table") + fetched = ref.fetch() + self.assertIsNotNone(fetched) + self.assertEqual(fetched.size, 20) + plugin_client.close() + + def test_publish_fetch_table(self): + export_ticket = self.session.fetch(ScopeTicket.scope_ticket("source")) + shared_ticket = SharedTicket.random_ticket() + self.session.publish(export_ticket, shared_ticket) + + sub_session = Session() + sub_export_ticket = sub_session.fetch(shared_ticket) + sub_table = sub_session.table_service.fetch_etcr(sub_export_ticket.pb_ticket) + self.assertEqual(sub_table.size, 20) + if __name__ == "__main__": unittest.main()