Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
50cfbbb
delete Configurator class
ludwiglierhammer Dec 17, 2025
e5faa59
__init__: build schema
ludwiglierhammer Dec 17, 2025
1a9fcbb
process textfilereader function
ludwiglierhammer Dec 17, 2025
432415f
methods to FileReader class
ludwiglierhammer Dec 17, 2025
0e69047
do not write to self
ludwiglierhammer Dec 18, 2025
3b0b15a
move all conversion and decoding to utils.convert_and_decode
ludwiglierhammer Dec 18, 2025
5f272e6
move validation to validator
ludwiglierhammer Dec 18, 2025
7444550
select_years more readable
ludwiglierhammer Dec 18, 2025
1bb4678
remove_boolean_values to util.utilities
ludwiglierhammer Dec 18, 2025
6e52dd2
introduce new module Parser
ludwiglierhammer Dec 18, 2025
49c2171
refactor Parser
ludwiglierhammer Dec 18, 2025
22e04df
get empty dict if not available
ludwiglierhammer Dec 18, 2025
0f597a2
import Decimal.InvalidOperator
ludwiglierhammer Dec 18, 2025
d18009c
minor fixes
ludwiglierhammer Dec 18, 2025
189a5dd
comment failing tests
ludwiglierhammer Dec 18, 2025
511f8b9
update parser
ludwiglierhammer Dec 18, 2025
f051cd5
update data processing
ludwiglierhammer Dec 18, 2025
a20b1a5
remove MDFFileReader
ludwiglierhammer Dec 18, 2025
5c69177
typo
ludwiglierhammer Dec 18, 2025
74680e7
set default encoding from schema
ludwiglierhammer Dec 18, 2025
d6634f5
set parse_dates
ludwiglierhammer Dec 18, 2025
d929b73
add netcdf parsing
ludwiglierhammer Dec 19, 2025
ffb3470
tests for select yearss with C-RAID
ludwiglierhammer Dec 19, 2025
a87aa25
set disabled columns to np.nan only if available in maks
ludwiglierhammer Dec 19, 2025
2986491
all parser functions to utils.parser
ludwiglierhammer Dec 19, 2025
24b05bb
make FileReader more flexible
ludwiglierhammer Dec 19, 2025
0213ce2
rework imports
ludwiglierhammer Dec 19, 2025
bc266e5
minor fixes
ludwiglierhammer Dec 19, 2025
2ae0323
replace schema with element attributes from parser
ludwiglierhammer Dec 19, 2025
ad62743
working with chunksize
ludwiglierhammer Dec 22, 2025
050c27a
rework schema reader
ludwiglierhammer Dec 22, 2025
43f7349
read_mdf with new parameter 'excludes'
ludwiglierhammer Dec 22, 2025
ffba642
validate types of arguments sections and excludes
ludwiglierhammer Jan 5, 2026
4402a16
handle both sections and excluides
ludwiglierhammer Jan 5, 2026
5b9ef9e
fixing excludes tests
ludwiglierhammer Jan 5, 2026
1326f3a
make validators more readable
ludwiglierhammer Jan 5, 2026
e36a132
column-based approach
ludwiglierhammer Jan 5, 2026
f87ff64
make validator more readable
ludwiglierhammer Jan 6, 2026
66983b2
no use of logging.basicConfig
ludwiglierhammer Jan 6, 2026
8ec51a6
make reader more readable
ludwiglierhammer Jan 6, 2026
b81f9d9
make writer more readable
ludwiglierhammer Jan 6, 2026
fa0a09f
some helper functions
ludwiglierhammer Jan 6, 2026
177dbc9
add type hints
ludwiglierhammer Jan 7, 2026
615c1a0
introcude ParserConfig class
ludwiglierhammer Jan 7, 2026
e6a12b0
simplify build_config
ludwiglierhammer Jan 7, 2026
3340ec7
minor code revisions
ludwiglierhammer Jan 7, 2026
9e9a32b
make FileReader more indepentend from Parser
ludwiglierhammer Jan 7, 2026
6bda860
remove orders from ParseConfig
ludwiglierhammer Jan 7, 2026
7884e07
make schemas more readable
ludwiglierhammer Jan 7, 2026
eaebf89
make parser functions stand-alone
ludwiglierhammer Jan 7, 2026
7ec61ee
some parser reviions
ludwiglierhammer Jan 8, 2026
7f5af24
some speed ups
ludwiglierhammer Jan 8, 2026
a11d403
remove some redundant lines
ludwiglierhammer Jan 8, 2026
644dc7d
add docstings and type hints
ludwiglierhammer Jan 8, 2026
734e2f5
add unit tests
ludwiglierhammer Jan 8, 2026
f2ed059
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 8, 2026
58dad7a
use order specs directly as input for parser function
ludwiglierhammer Jan 9, 2026
038168d
add docstings
ludwiglierhammer Jan 9, 2026
6e84d64
add more parser tests
ludwiglierhammer Jan 9, 2026
45c7836
Merge branch 'rework_reader' of https://github.com/ludwiglierhammer/c…
ludwiglierhammer Jan 9, 2026
bb69613
do not save redundant information
ludwiglierhammer Jan 9, 2026
1ceeff6
more doctrings and unnit tests
ludwiglierhammer Jan 9, 2026
da92bfd
codespell: exclude tests
ludwiglierhammer Jan 9, 2026
5964308
update docstrings
ludwiglierhammer Jan 9, 2026
11b8703
add more tests
ludwiglierhammer Jan 9, 2026
be6a744
remove unused imports
ludwiglierhammer Jan 9, 2026
9656666
make both ext_schema_file and exT_schema_path explicitly
ludwiglierhammer Jan 9, 2026
5fdfbb1
convert records to list
ludwiglierhammer Jan 12, 2026
cbe75a5
specify column name renaming
ludwiglierhammer Jan 12, 2026
98e3fe5
leave df as a DataFrame
ludwiglierhammer Jan 12, 2026
31367bc
add more tests
ludwiglierhammer Jan 12, 2026
6d15a97
update validate_read_mdf_args
ludwiglierhammer Jan 12, 2026
0b5ab2b
typop
ludwiglierhammer Jan 12, 2026
4afd1de
update CHANGELOG
ludwiglierhammer Jan 12, 2026
3c430c9
Merge branch 'main' into rework_reader
ludwiglierhammer Jan 12, 2026
10a73b8
set optionals
ludwiglierhammer Jan 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ repos:
hooks:
- id: codespell
additional_dependencies: [ 'tomli' ]
exclude: tests/.*\.py
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.31.1
hooks:
Expand Down
19 changes: 18 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ New features and enhancements

Breaking changes
^^^^^^^^^^^^^^^^
* ``cdm_reader_mapper.cdm_mapper``: rename `map_and_covnert` to helper function `_map_and_convert` (:pull:`343`)
* ``cdm_reader_mapper.cdm_mapper``: rename `map_and_convert` to helepr function `_map_and_convert` (:pull:`343`)
* replace `logging.error` with `raise` error statements (:pull:`345`)

Internal changes
^^^^^^^^^^^^^^^^
Expand All @@ -34,6 +35,22 @@ Internal changes
* ``cdm_reader_mapper.cdm_mapper``: introduce some helper functions (:pull:`324`)
* add more unit tests (:issue:`311`, :pull:`324`)
* ``cdm_reader_mapper.cdm_mapper``: split `map_and_convert` into multiple helper functions (:issue:`333`, :pull:`343`)
* exclude tests/*.py from `pre-commit` codespell hook (:pull:`345`)
* replace many `os` functions with `pathlib.Path` (:pull:`345`)
* re-work `mdf_reader` (:issue:`334`, :pull:`345`)

* remove `reader.MDFFileReader` class
* remove `utils.configurator` module
* remove both `utils.decoder` and `mdf_reader.utils.converter` modules
* introduce `utils.parser` module: bunch of functions to parse input data into MDF data
* introduce `utils.convert_and_decode`: make converter and decoder functions more modular
* make `utils.validator` module more modular
* `utils.filereader.FileReader` uses `utils.parser` function for parsing
* move many helper function to `utils.utilities`
* serialize `schemas.schemas` module

* add type hints and docstrings to `mdf_reader` (:pull:`345`)
* add unit tests for `mdf_reader` module to testing suite (:pull:`345`)

Bug fixes
^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion cdm_reader_mapper/common/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import pandas as pd

from cdm_reader_mapper.common import pandas_TextParser_hdlr
from . import pandas_TextParser_hdlr


def _count_by_cat(series) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion cdm_reader_mapper/common/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import pandas as pd

from cdm_reader_mapper.common import logging_hdlr
from . import logging_hdlr


def replace_columns(
Expand Down
75 changes: 40 additions & 35 deletions cdm_reader_mapper/mdf_reader/codes/codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

from __future__ import annotations

import logging
import os
from pathlib import Path

from cdm_reader_mapper.common.json_dict import (
Expand All @@ -23,53 +21,60 @@


def read_table(
code_table_name,
imodel=None,
ext_table_path=None,
code_table_name: str,
imodel: str | None = None,
ext_table_path: str | None = None,
) -> dict:
"""
Read a data model code table file to a dictionary.
Load a data model code table into a Python dictionary.

It completes the code table to the full complexity
the data reader expects, by appending information
on secondary keys and expanding range keys.
The code table may define secondary keys, range expansions, or other
structures required by the data reader. This function resolves the
file location either from an external path or an internal data model.

Parameter
---------
code_table_name: str
The external code table file.
imodel: str, optional
Name of internally available input data model.
e.g. icoads_r300_d704
ext_table_path: str, optional
The path to the external code table file.
One of ``imodel`` and ``ext_table_path`` must be set.
Parameters
----------
code_table_name : str
The name of the code table (without file extension).
e.g., `"ICOADS.C0.IM"`
imodel : str, optional
Internal data model name, e.g., `"icoads_r300_d704"`. Required if
`ext_table_path` is not provided.
ext_table_path : str, optional
External path containing the code table file. If set, this path
takes precedence over `imodel`.

Returns
-------
dict
Code table
Dict
The fully combined code table dictionary.

Raises
------
FileNotFoundError
If the specified table file cannot be found.
ValueError
If neither `imodel` nor `ext_table_path` is provided.
"""
# 1. Validate input
if ext_table_path:
table_path = os.path.abspath(ext_table_path)
table_files = os.path.join(table_path, code_table_name + ".json")
if not os.path.isfile(table_files):
logging.error(f"Can't find input code table file {table_files}")
return
table_files = Path(table_files)
else:
imodel = imodel.split("_")
table_path = Path(ext_table_path).resolve()
table_file = table_path / f"{code_table_name}.json"
if not table_file.is_file():
raise FileNotFoundError(f"Can't find input code table file {table_file}")
table_files = [table_file]
elif imodel:
parts = imodel.split("_")
table_files = collect_json_files(
*imodel,
*parts,
base=f"{properties._base}.codes",
name=code_table_name,
)

if isinstance(table_files, Path):
table_files = [table_files]
# 2. Get tables
if isinstance(table_files, Path):
table_files = [table_files]
else:
raise ValueError("One of 'imodel' or 'ext_table_path' must be set")

tables = [open_json_file(ifile) for ifile in table_files]

# 3. Combine tables
return combine_dicts(tables)
Loading
Loading