Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude vars from catalogs in parse_directory #107

Merged
merged 1 commit into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.rst
Expand Up @@ -8,6 +8,7 @@ Contributors to this version: Gabriel Rondeau-Genesse (:user:`RondeauG`), Juliet

New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Possibility of excluding variables read from file from the catalog produced by ``parse_directory``. (:pull:`107`).

Breaking changes
^^^^^^^^^^^^^^^^
Expand Down
9 changes: 7 additions & 2 deletions xscen/catalog.py
Expand Up @@ -883,6 +883,7 @@ def parse_directory(
Dictionary with mapping from parsed name to controlled names for each column.
May have an additionnal "attributes" entry which maps from attribute names in the files to
official column names. The attribute translation is done before the rest.
In the "variable" entry, if a name is mapped to None (null), that variable will not be listed in the catalog.
xr_open_kwargs: dict
If needed, arguments to send xr.open_dataset() when opening the file to read the attributes.
parallel_depth: int
Expand Down Expand Up @@ -1014,8 +1015,12 @@ def read_first_file(grp, cols):
# Variable can be a tuple, we still want to replace individual names through the cvs
df["variable"] = df.variable.apply(
lambda vs: vs
if isinstance(vs, str)
else tuple(cvs["variable"].get(v, v) for v in vs)
if isinstance(vs, str) or pd.isnull(vs)
else tuple(
cvs["variable"].get(v, v)
for v in vs
if cvs["variable"].get(v, v) is not None
)
)

# translate xrfreq into frequencies and vice-versa
Expand Down