From 53448d4ef153fd262466087a951bc28a44c8fadf Mon Sep 17 00:00:00 2001 From: Manfred Cheung Date: Tue, 30 Apr 2024 15:42:51 -0400 Subject: [PATCH] added support for from_json for json containing predicates (#562) added support for from_json for json containing predicates --- CHANGELOG.md | 6 ++++++ graphistry/compute/ast.py | 4 +++- graphistry/tests/compute/test_chain.py | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea4821aeb..e2ab8fa7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Development] +## [0.33.8 - 2024-04-30] + +### Added + +* Fix from_json when json object contains predicates. + ## [0.33.7 - 2024-04-06] * Fix refresh() for SSO diff --git a/graphistry/compute/ast.py b/graphistry/compute/ast.py index c1e7b4e04..d478c23f2 100644 --- a/graphistry/compute/ast.py +++ b/graphistry/compute/ast.py @@ -10,6 +10,8 @@ from graphistry.util import setup_logger from graphistry.utils.json import JSONVal, is_json_serializable from .predicates.ASTPredicate import ASTPredicate +from .predicates.from_json import from_json as predicates_from_json + from .predicates.is_in import ( is_in, IsIn ) @@ -100,7 +102,7 @@ def maybe_filter_dict_from_json(d: Dict, key: str) -> Optional[Dict]: return None if key in d and isinstance(d[key], dict): return { - k: ASTPredicate.from_json(v) if isinstance(v, dict) else v + k: predicates_from_json(v) if isinstance(v, dict) else v for k, v in d[key].items() } elif key in d and d[key] is not None: diff --git a/graphistry/tests/compute/test_chain.py b/graphistry/tests/compute/test_chain.py index c685edb84..ea3fb232e 100644 --- a/graphistry/tests/compute/test_chain.py +++ b/graphistry/tests/compute/test_chain.py @@ -44,6 +44,19 @@ def test_chain_serialization_multi(): o2 = d.to_json() assert o == o2 +def test_chain_serialization_pred(): + o = Chain([n(query='zzz', name='abc', filter_dict={'a': is_in(options=['a', 'b', 'c'])}), + e(edge_query='zzz', name='abc', edge_match={'b': is_in(options=['a', 'b', 'c'])})]).to_json() + d = Chain.from_json(o) + assert isinstance(d.chain[0], ASTNode) + assert d.chain[0].query == 'zzz' + assert d.chain[0]._name == 'abc' + assert isinstance(d.chain[1], ASTEdge) + assert d.chain[1].edge_query == 'zzz' + assert d.chain[1]._name == 'abc' + o2 = d.to_json() + assert o == o2 + def test_chain_simple_cudf_pd(): nodes_df = pd.DataFrame({'id': [0, 1, 2], 'label': ['a', 'b', 'c']}) edges_df = pd.DataFrame({'src': [0, 1, 2], 'dst': [1, 2, 0]})