Skip to content

Commit

Permalink
Merge branch 'main' into coverage-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre authored Mar 1, 2024
2 parents 6643438 + 74b35e4 commit 4a59ec4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
- Added support for running `pytest` with `pytest-cov`. By @Zeitsperre
- Reworked the GitHub CI testing workflow to perform version checks as well as tests with `pytest-cov` . By @Zeitsperre

**Breaking changes**
Breaking changes
^^^^^^^^^^^^^^^^
- Nested group handling:
Before this version, all groups were read, but conflicting variable names in-between groups would shadow data. Now, similarly to xarray ``open_dataset``, ``open_ncml`` accepts an optional ``group`` argument to specify which group should be read. When ``group`` is not specified, it defaults to the root group. Additionally ``group`` can be set to ``'*'`` so that every group is read and the hierarchy is flattened. In the event of conflicting variable/dimension names across groups, the conflicting name will be modified by appending ``'__n'`` where n is incremented.
- Enums are no longer transformed into CF flag_values and flag_meanings attributes, instead they are stored in the ``encoding["dtype"].metadata`` of their respective variable. This is aligned with what is done on xarray v2024.01.0
- [fix] scalar attributes that are not strings are no longer wrapped in tuples of length 1.

0.4.0 (2024-01-08)
==================
Expand All @@ -16,7 +18,7 @@
- Update XSD schema and dataclasses to latest version from netcdf-java to add support
for unsigned types. By @bzah
- Add support for scalar variables. By @Bzah
- [fix] empty attributes now are parsed into an empty string instead of crashing the parser. By @Bzah
- [fix] empty attributes are now parsed into an empty string instead of crashing the parser. By @Bzah

0.3.1 (2023-11-10)
==================
Expand Down
5 changes: 5 additions & 0 deletions tests/data/testDoubleAttr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<attribute name="toto" type="double" value="42.42" />
<attribute name="comment" value="" />
</netcdf>
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ def test_flatten_groups__sub_groups():
assert ds['a_var__2'].size == 22


def test_read_non_str_attribute():
ds = xncml.open_ncml(data / 'testDoubleAttr.xml')
assert ds.attrs['toto'] == 42.42


# --- #
def check_dimension(ds):
assert len(ds['lat']) == 3
Expand Down
3 changes: 2 additions & 1 deletion xncml/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,10 @@ def cast(obj: Attribute) -> tuple | str:
if value:
if obj.type in [DataType.STRING, DataType.STRING_1]:
return value

sep = obj.separator or ' '
values = value.split(sep)
if len(values) == 1:
return nctype(obj.type)(values[0])
return tuple(map(nctype(obj.type), values))
return ''

Expand Down

0 comments on commit 4a59ec4

Please sign in to comment.