feat(melodi): tests, docstrings, fix measures parsing#308
Conversation
Signed-off-by: GrasClement <gras.clement@orange.fr>
Signed-off-by: GrasClement <gras.clement@orange.fr>
Signed-off-by: GrasClement <gras.clement@orange.fr>
Signed-off-by: GrasClement <gras.clement@orange.fr>
Signed-off-by: GrasClement <gras.clement@orange.fr>
|
Hi, The JDOS are done, here is a quick closure summary for this PR, Bug Fixes
New Content
Code Maintenance
Cheers |
|
Thanks @GrasClement ! |
|
Hi @GrasClement , sorry I took so long to review this, I was overloaded at work. So I finally took the time to do it, with the exception of testing the documentation (I'm in a train on a personnal windows machine...) though it looks ok to me. I've made some comments: depending of your available time, feel free to let me know if you haven't the time to check all of this. In any case, thank you for both your great work and the effort to uniformize the API with the silent/update kwargs ❤️ ! |
|
Hi @tgrandje, no worries about the timing, and thanks for taking the time to review the PR! I don't seem to see any review comments or additional commits attached to the PR yet. Whenever you have a chance, could you check whether the comments were actually submitted? Or maybe the issue is on my side and I'm looking in the wrong place. I'd be happy to go through your feedback and update the PR once this is sorted out 😎 |
tgrandje
left a comment
There was a problem hiding this comment.
Sorry @GrasClement I forgot to submit the review 😳 !
| # déplie toutes les clés de mesure dynamiquement | ||
| # (le nom varie selon le dataset : OBS_VALUE_NIVEAU, OBS_VALUE_INDICE_DE_PRIX, etc.) |
There was a problem hiding this comment.
Should we switch the comments to english?
| measures_expanded = pd.DataFrame( | ||
| obs["measures"] | ||
| .apply(lambda m: {k: v.get("value") for k, v in m.items()}) | ||
| .tolist() | ||
| ) |
There was a problem hiding this comment.
Isn't the key unique in a dataset? If that's the case maybe we could avoid the whole apply process, what do you think?
| @@ -664,8 +764,9 @@ def get_idbank( | |||
| # test = get_range("DS_TICM_PRATIQUES", include_values=True) | |||
There was a problem hiding this comment.
While you're at it, would you mind removing the tailing tests under the if __name__ == "__main__" block?
| # Exception here: the bugs fixed in melodi/data/py live inside parsing helpers | ||
| # called inside get_dataset. Testing them through the real API would | ||
| # require downloading DS_IPC_PRINC on every test run. |
There was a problem hiding this comment.
Thanks for the explanations! As pynsee was never (yet) released with MELODI api, what do you think of removing the comments detailing the tests' purposes as fixes to my original branch? In case you're ok, I'll flag the involved comments I've seen.
|
|
||
| def test_get_catalog_known_datasets_present(self): | ||
| # dataset_identifier is not unique (one dataset can have multiple products). | ||
| # Assert presence of stable, long-running datasets rather than len > 0. |
There was a problem hiding this comment.
It took me a while to understand what you meant with the "rather tan len > 0". Maybe we could also remove that part, as it doesn't bring anything useful (I think): I let you be the judge on that 😉 ! (Note: it might very well just me being daft...)
| self.assertTrue(test) | ||
|
|
||
| def test_parse_observations_no_measures_column(self): | ||
| # Regression: observations without "measures" must not crash. |
There was a problem hiding this comment.
Update commentary in context with pynsee's release with brand new MELODI api? (maybe just remove the regression part?)
|
|
||
| def test_get_idbank_series_history_stable(self): | ||
| # 010770930 = DS_ICA monthly series, sector 46.19A (non-food purchasing | ||
| # centres), base 2021. Open series: do NOT assert len (grows monthly). |
There was a problem hiding this comment.
I get it we shouldn't check the len, but that does'nt mean we couldn't check wether it's still updated. I was thinking of something like (df.groupby(df["TIME_PERIOD"].str[:4])["dataset"].count()[:-1]==12).all(), what do you think?
| # Regression: "key2 in {'all', language}" was backwards: _fr columns | ||
| # were absent when language="fr". Fixed to "language in {'all', key2}". |
There was a problem hiding this comment.
Update commentary in context with pynsee's release with brand new MELODI api?
|
|
||
| def test_get_idbank_dead_bdm_ids(self): | ||
| # BDM series with no MELODI dataset yet -> HTTP 200 + empty list -> empty df. | ||
| df = get_idbank("001565530+001565531") |
There was a problem hiding this comment.
I'm thinking this would be better yet to do something quite explicit with a df = get_idbank("spam+eggs"); for those of us outside INSEE, it's not the most convenient of things to retrieve idbanks and check if they have associated data 😉 . By the way, should we log a warning stating that no data was retrieved and that is not a pynsee error?
|
|
||
| MELODI | ||
| ------ | ||
|
|
||
| .. automodule:: pynsee.melodi | ||
| :members: |
There was a problem hiding this comment.
What do you think of putting MELODI before utils? I'd even go as far as setting it where METADATA was (and setting METADATA at the latest position in regard of it's deprecation).
Draft contribution aux JDOS : cible la branche #306
_parse_dataset_observations(voir package R Melodi)