Skip to content

Commit

Permalink
extract: Fix extracting from sparse datagrams if key is missing. (#51)
Browse files Browse the repository at this point in the history
* Comments in electrochem

* Allow newer dgbowl-schema

* Sparse extract test

* Return an empty dict.
  • Loading branch information
PeterKraus authored Aug 16, 2022
1 parent 3be0d39 commit add39a9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"chemicals>=1.0.0",
"rdkit-pypi>=2022",
"yadg>=4.1",
"dgbowl-schemas==106",
"dgbowl-schemas>=106",
"matplotlib>=3.5.0",
],
extras_require={
Expand Down
6 changes: 4 additions & 2 deletions src/dgpost/transform/electrochemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def charge(
----------
time
An array of timestamps at which the instantaneous current was measured.
Defaults to the :class:`pd.Index` of the :class:`pd.DataFrame`.
I
Values of the instantaneous current.
Expand Down Expand Up @@ -273,9 +274,10 @@ def average_current(
----------
time
An array of timestamps at which the instantaneous current was measured.
Defaults to the :class:`pd.Index` of the :class:`pd.DataFrame`.
I
Values of the instantaneous current.
Q
Values of the overall charge.
t0
An optional timestamp representing the time at which charge was zero. If not
Expand Down
2 changes: 1 addition & 1 deletion src/dgpost/utils/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _get_key_recurse(data, keylist):
for i in ret
]
):
return _get_key_recurse([i[key] for i in data], ["*"])
return _get_key_recurse([i.get(key, {}) for i in data], ["*"])
else:
return [None], [ret]
else:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ def test_valid_datagram(datadir):
},
"ref.ca.single.pkl",
),
( # ts12 - sparse extract with arrow and implicit
"sparse.dg.json",
{
"at": {"step": "a"},
"columns": [
{"key": "derived->xin->*", "as": "a"},
{"key": "derived->xin", "as": "b"},
],
},
"ref.sparse.xin.pkl",
),
],
)
def test_extract_single(inpath, spec, outpath, datadir):
Expand Down
Binary file added tests/test_extract/ref.sparse.xin.pkl
Binary file not shown.

0 comments on commit add39a9

Please sign in to comment.