Skip to content

melodi - #306

Open
tgrandje wants to merge 16 commits into
masterfrom
feat/melodi
Open

melodi#306
tgrandje wants to merge 16 commits into
masterfrom
feat/melodi

Conversation

@tgrandje

@tgrandje tgrandje commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@tgrandje tgrandje self-assigned this Apr 7, 2026
@tgrandje tgrandje changed the title melodi catalog melodi Apr 7, 2026
@tgrandje

Copy link
Copy Markdown
Collaborator Author

@hadrilec @linogaliana @tfardet @RLesur do any of you guys see the point in covering MELODI's "référentiel" endpoint through pynsee?

It doesn't seem to be used in the R package and I have no usecase in my mind right now (that and the fact that the json returned seem overly complex to be used in a generic way)...

@tgrandje

Copy link
Copy Markdown
Collaborator Author

Note: 2 tickets have been opened on INSEE's API portal.

  • one regarding problems with pagination (for instance querying DS_POPULATIONS_REFERENCE with no filters). I don't think any workaround can be done for this in pynsee.
  • one regarding X-INSEE-Api-Key-Integration header were MELODI seems to confuse the header with the one used for SIRENE consumption. I've added a fix in pynsee in the PynseeAPISession object.

@hadrilec

hadrilec commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Hi, I had started in the branch catalog to write a function retrieving the list of datasets available via melodi. On the long term, I think it makes sense, as I understand more INSEE datasets shall be available melodi. I understand that DoReMiFaSol already uses melodi: https://github.com/InseeFrLab/DoReMIFaSol

@tgrandje

Copy link
Copy Markdown
Collaborator Author

Hi @hadrilec , I've already re-used your code for the catalog (which I also think is gonna be madatory). I was instead speaking of the "référentiel" endpoint and I haven't quite seen the point (yet ?).

Right now, you got catalog (as already said), you got all available dimensions and values for a given dataset using the "range" endpoint : it seems to me that's enough ?

GrasClement and others added 4 commits October 14, 2026 11:08
* add .vscode to gitignore

* add notebooks to gitignore

* wip docstrings and fixes data.py

* fix measures column issue in _parse_dataset_observations

* fix(melodi): handle non-MELODI idbanks

* test(melodi): add pytest coverage and fix update/silent signatures

Signed-off-by: GrasClement <gras.clement@orange.fr>

* test(melodi): finish tests for melodi

Signed-off-by: GrasClement <gras.clement@orange.fr>

* doc(melodi): add melodi to the documentation

Signed-off-by: GrasClement <gras.clement@orange.fr>

* doc(melodi): linting

Signed-off-by: GrasClement <gras.clement@orange.fr>

* doc(melodi): fix spacing

Signed-off-by: GrasClement <gras.clement@orange.fr>

* fix(melodi): simplify measures parsing, log empty idbank results

Signed-off-by: GrasClement <gras.clement@orange.fr>

* test(melodi): fix redundant checks and update comments per review

Signed-off-by: GrasClement <gras.clement@orange.fr>

* doc(melodi): reorder modules and flag metadata as deprecated

Signed-off-by: GrasClement <gras.clement@orange.fr>

---------

Signed-off-by: GrasClement <gras.clement@orange.fr>
Co-authored-by: cgras <clement.gras@ccomptes.fr>
@tgrandje
tgrandje marked this pull request as ready for review October 14, 2026 09:31
@tgrandje
tgrandje requested a review from tfardet October 14, 2026 09:57
@tgrandje

Copy link
Copy Markdown
Collaborator Author

This should be ok, let's review @tfardet when you got time enough !

@tfardet tfardet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tgrandje and @GrasClement for this new additions.
I have a few points of discussions that I opened regarding naming and descriptions, let me know what you think.

Comment thread pynsee/melodi/data.py
Comment on lines +417 to +421
Get a dataset's available dimensions (ie "ranges").

Available dimensions can be retrieved in a sparse format (with only
the dimensions' descriptions) or a long format (including all available
values for each dimension).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried that this would not be very easy to understand for newcomers.
Should we maybe just start with "columns' names", then say that these can be called dimensions or ranges? I'm also wondering why we need to introduce an additional way of naming them with "dimension".

Same with the "sparse" format, since there is no "sparse" keyword, if it is mentioned there (should it be?), I think it should be associated to include_values to make the link explicit.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh, true enough. Fact is, the swagger currently describes "range[s]" in the endpoint, "dimensions et modalités" in the french description. To be coherent with API, I think we should stick to the "range" denomination, but that one is a bit obscure to me...

Comment thread pynsee/melodi/data.py Outdated
Comment thread pynsee/melodi/data.py


@save_df(day_lapse_max=30)
def get_idbank(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be renamed to get_series_by_idbank/get_data_by_idbank or something similar?
current name feels misleading to me (I'd expect that the function helps me look for an idbank given a name or keywords)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I'd go as far as to rename it as get_series as in macrodata ; do you have on objection on that (arguments will not be the same, but the logic stands I think).

Comment thread pynsee/melodi/data.py
arguments should NOT be added to the kwargs and will be ignored. `range`
will also be ignored : to retrieve a dataset's dimensions, have a look at
`pynsee.melodi.get_range`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to numpy format:

Note
----

Comment thread pynsee/melodi/data.py Outdated
from typing import Optional, Union
import warnings
from functools import lru_cache
from typing import Optional, Union

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are not needed anymore at the Python versions we support; should we take the opportunity to move to | bit by bit or do we want to keep that for a single PR that covers the whole code?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to make a full PR for python >= 3.11 instead? (I was also wondering how I came with the python >=3.10 in the pyproject.toml, I suspect I encountered dependencies conflicts at some point).

Comment thread pynsee/utils/requests_session.py Outdated
Comment thread pynsee/__init__.py
from pynsee.download import *

__version__ = "0.2.5"
__version__ = "0.2.6"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to discuss this, that's not a bugfix release (long overdue, I'm afraid, my fault), we should probably jump to 0.3.0

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right. Do you wan the 0.3.0 in here or in a ad hoc PR before release (I'm in favour of the 2nd option).

Comment thread pyproject.toml
"statistique", "démographie", "géospatial", "SIG"
]
requires-python = ">=3.9"
requires-python = ">=3.10"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move to 3.11? 3.10 is no longer maintained? (I've no strong opinion about this)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that PR was started some time ago 😄 ! Il fix this to 3.11, but we need a more serious PR for this afterwards (including badges, dependencies checkup, ...)

Comment thread tests/melodi/__init__.py
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the file? I don't think we do with pytest

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, good question, I'll double check. If that's not needed anymore, I'll remove the other ones from previous tests.

tgrandje and others added 3 commits October 14, 2026 20:19
Co-authored-by: tfardet <79037344+tfardet@users.noreply.github.com>
Co-authored-by: tfardet <79037344+tfardet@users.noreply.github.com>
Co-authored-by: tfardet <79037344+tfardet@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants