From add39a921af765cc835f778ef2f33ac69c91acd6 Mon Sep 17 00:00:00 2001 From: Peter Kraus Date: Tue, 16 Aug 2022 20:04:36 +0800 Subject: [PATCH] `extract`: Fix extracting from sparse datagrams if key is missing. (#51) * Comments in electrochem * Allow newer dgbowl-schema * Sparse extract test * Return an empty dict. --- setup.py | 2 +- src/dgpost/transform/electrochemistry.py | 6 ++++-- src/dgpost/utils/extract.py | 2 +- tests/test_extract.py | 11 +++++++++++ tests/test_extract/ref.sparse.xin.pkl | Bin 0 -> 3520 bytes 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 tests/test_extract/ref.sparse.xin.pkl diff --git a/setup.py b/setup.py index 3859340..c3357b8 100644 --- a/setup.py +++ b/setup.py @@ -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={ diff --git a/src/dgpost/transform/electrochemistry.py b/src/dgpost/transform/electrochemistry.py index e6db26f..f85d632 100644 --- a/src/dgpost/transform/electrochemistry.py +++ b/src/dgpost/transform/electrochemistry.py @@ -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. @@ -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 diff --git a/src/dgpost/utils/extract.py b/src/dgpost/utils/extract.py index 5d07bb1..8b64631 100644 --- a/src/dgpost/utils/extract.py +++ b/src/dgpost/utils/extract.py @@ -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: diff --git a/tests/test_extract.py b/tests/test_extract.py index 7d6d4e1..8fcfb8f 100644 --- a/tests/test_extract.py +++ b/tests/test_extract.py @@ -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): diff --git a/tests/test_extract/ref.sparse.xin.pkl b/tests/test_extract/ref.sparse.xin.pkl new file mode 100644 index 0000000000000000000000000000000000000000..ce9114b248149a2a43c2cb42ba3563e8ff56aad6 GIT binary patch literal 3520 zcmb`K&5ImG7{+_Pb|;&-VI#(sNc=!?mxRGY(LJa`G9hd1q$LJ|1VdBZU9;7lp6;Q# zdgDNXo5SoTP~c%pQ4e|$1VN8tPB{qP;>kn)f!yLj1VK;nt?r(go^)7hXY6JBqvoyO z`_@z4#Zw!#&whGBOAfx!MS+8&h8=FBG!lH@Nk6o&oJ*g@HuOB0buoR{iW6GZc; zg1FP|rPXv|pSg%q)B~(Zu^k2xqp{6oU@Zw0d={!tLbipj^+l^>i7oMgSkg=ISKSn3 zKd(8g*Tu3^`TZ4f>t_0Ug_o`g!!X`^2uE_#n@m`@Et@6p)4}Vq_k0WazRZ1rIj5j$Tdbx%G#K*@5nJSiv?TJ< zum;70{OCR|0YPAFWq0*=bQqmVT(TmkUwE&+v4?(VdJ-xUCv za8Tz@>b^qOyl@4;gIxj&!u>TZ;9mtmCR|OQnM}CCQsd2)G)*CKPP-ywL5-ob zVtI>duuO>=eReV>3TuwHtd=;ZM3M381dK$?x=6J@(>)4NE4$puxy|ZxQwR}j` z0Z%Q8#-$7{Cb2ENgailoD(mOfKpJr)-UPdo5-$P~Qh6W3wMeNBDdiL3(yOi4-dzE^ zYaExJ_jtne5cEumnAhyk!AZURK+bW)EvBw5_+GP3!KudWHl`rQQmZb%kP;k%Eb_8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