Skip to content

Commit

Permalink
added support for from_json for json containing predicates (#562)
Browse files Browse the repository at this point in the history
added support for from_json for json containing predicates
  • Loading branch information
mj3cheun authored Apr 30, 2024
1 parent 4cc316b commit 53448d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion graphistry/compute/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions graphistry/tests/compute/test_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
Expand Down

0 comments on commit 53448d4

Please sign in to comment.