Skip to content

Commit 53448d4

Browse files
authored
added support for from_json for json containing predicates (#562)
added support for from_json for json containing predicates
1 parent 4cc316b commit 53448d4

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
77

88
## [Development]
99

10+
## [0.33.8 - 2024-04-30]
11+
12+
### Added
13+
14+
* Fix from_json when json object contains predicates.
15+
1016
## [0.33.7 - 2024-04-06]
1117

1218
* Fix refresh() for SSO

graphistry/compute/ast.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from graphistry.util import setup_logger
1111
from graphistry.utils.json import JSONVal, is_json_serializable
1212
from .predicates.ASTPredicate import ASTPredicate
13+
from .predicates.from_json import from_json as predicates_from_json
14+
1315
from .predicates.is_in import (
1416
is_in, IsIn
1517
)
@@ -100,7 +102,7 @@ def maybe_filter_dict_from_json(d: Dict, key: str) -> Optional[Dict]:
100102
return None
101103
if key in d and isinstance(d[key], dict):
102104
return {
103-
k: ASTPredicate.from_json(v) if isinstance(v, dict) else v
105+
k: predicates_from_json(v) if isinstance(v, dict) else v
104106
for k, v in d[key].items()
105107
}
106108
elif key in d and d[key] is not None:

graphistry/tests/compute/test_chain.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ def test_chain_serialization_multi():
4444
o2 = d.to_json()
4545
assert o == o2
4646

47+
def test_chain_serialization_pred():
48+
o = Chain([n(query='zzz', name='abc', filter_dict={'a': is_in(options=['a', 'b', 'c'])}),
49+
e(edge_query='zzz', name='abc', edge_match={'b': is_in(options=['a', 'b', 'c'])})]).to_json()
50+
d = Chain.from_json(o)
51+
assert isinstance(d.chain[0], ASTNode)
52+
assert d.chain[0].query == 'zzz'
53+
assert d.chain[0]._name == 'abc'
54+
assert isinstance(d.chain[1], ASTEdge)
55+
assert d.chain[1].edge_query == 'zzz'
56+
assert d.chain[1]._name == 'abc'
57+
o2 = d.to_json()
58+
assert o == o2
59+
4760
def test_chain_simple_cudf_pd():
4861
nodes_df = pd.DataFrame({'id': [0, 1, 2], 'label': ['a', 'b', 'c']})
4962
edges_df = pd.DataFrame({'src': [0, 1, 2], 'dst': [1, 2, 0]})

0 commit comments

Comments
 (0)