From 3705c123bd91c6cd7bc7a76183cd2c1630d23ce6 Mon Sep 17 00:00:00 2001 From: Wolfgang Preimesberger Date: Tue, 8 Oct 2024 11:31:31 +0200 Subject: [PATCH 1/2] Fix append mode attribute updates --- .github/workflows/ubuntu.yml | 20 ++++++++++---------- .github/workflows/windows.yml | 10 +++++----- environment.yml | 2 -- setup.cfg | 1 - src/pynetcf/base.py | 4 ++-- src/pynetcf/point_data.py | 2 +- src/pynetcf/time_series.py | 4 ++-- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 858204b..6a36b28 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -12,19 +12,19 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ['3.8', '3.9', '3.10'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] os: ["ubuntu-latest"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: - submodules: false # does not work with self-hosted testdata + submodules: false - name: Checkout Testdata shell: bash -l {0} run : | git submodule init git submodule update - - uses: conda-incubator/setup-miniconda@v2 + - uses: conda-incubator/setup-miniconda@v3 with: miniconda-version: "latest" auto-update-conda: true @@ -43,18 +43,18 @@ jobs: - name: Export Environment shell: bash -l {0} run: | - mkdir -p .artifacts + mkdir -p artifacts filename=env_py${{ matrix.python-version }}_${{ matrix.os }}.yml - conda env export --no-builds | grep -v "prefix" > .artifacts/$filename + conda env export --no-builds | grep -v "prefix" > artifacts/$filename - name: Upload Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: os_py_environments - path: .artifacts/* + name: Artifacts-py${{ matrix.python-version }}-${{ matrix.os }} + path: artifacts/* - name: Install package and test shell: bash -l {0} run: | - pip install -e . + pip install -e .[testing] pytest --cache-clear - name: Upload Coverage shell: bash -l {0} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 7d36c53..a682674 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -12,19 +12,19 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ['3.10'] + python-version: ['3.12'] os: ['windows-latest'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: - submodules: false # does not work with self-hosted testdata + submodules: false - name: Checkout Testdata shell: bash -l {0} run : | git submodule init git submodule update - - uses: conda-incubator/setup-miniconda@v2 + - uses: conda-incubator/setup-miniconda@v3 with: miniconda-version: "latest" auto-update-conda: true @@ -43,5 +43,5 @@ jobs: - name: Install package and test shell: bash -l {0} run: | - pip install -e . + pip install -e .[testing] pytest --cache-clear diff --git a/environment.yml b/environment.yml index ce28e6e..257d9b9 100644 --- a/environment.yml +++ b/environment.yml @@ -12,5 +12,3 @@ dependencies: - pip: - pygeobase - pygeogrids - - pytest - - pytest-cov diff --git a/setup.cfg b/setup.cfg index 53ec135..31d5305 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,7 +61,6 @@ exclude = # Add here test requirements (semicolon/line-separated) testing = - setuptools pytest pytest-cov diff --git a/src/pynetcf/base.py b/src/pynetcf/base.py index e6e393e..89a67db 100644 --- a/src/pynetcf/base.py +++ b/src/pynetcf/base.py @@ -286,7 +286,7 @@ def read_var(self, name): name of the variable """ - if self.mode in ["r", "r+"]: + if self.mode in ["r", "r+", "a"]: if name in self.dataset.variables.keys(): return self.dataset.variables[name][:] @@ -308,7 +308,7 @@ def flush(self): Flush data to disk. """ if self.dataset is not None: - if self.mode in ["w", "r+"]: + if self.mode in ["w", "r+", "a"]: self._set_global_attr() self.dataset.sync() diff --git a/src/pynetcf/point_data.py b/src/pynetcf/point_data.py index 70f8eb3..130a0e4 100644 --- a/src/pynetcf/point_data.py +++ b/src/pynetcf/point_data.py @@ -342,7 +342,7 @@ def write(self, # convert dict to recarray metadata = {"dims": md_dict} dtype = np.dtype(dtype_list, metadata=metadata) - data = np.core.records.fromarrays(data.values(), dtype=dtype) + data = np.rec.fromarrays(data.values(), dtype=dtype) for var_data in data.dtype.names: if var_data not in self.nc.variables: diff --git a/src/pynetcf/time_series.py b/src/pynetcf/time_series.py index 521799d..e222d27 100644 --- a/src/pynetcf/time_series.py +++ b/src/pynetcf/time_series.py @@ -309,7 +309,7 @@ def _get_loc_id_index(self, loc_id): loc_id = np.atleast_1d(loc_id) # check if the location ids are all actually in the location id # variable - in1d = np.in1d(loc_id, self.loc_ids_var.data, assume_unique=True) + in1d = np.isin(loc_id, self.loc_ids_var.data, assume_unique=True) if loc_id[in1d].size != loc_id.size: raise IOError("Location not yet defined") loc_ids_sorted = np.argsort(self.loc_ids_var.data) @@ -380,7 +380,7 @@ def _add_location(self, loc_id, lon, lat, alt=None, loc_descr=None): loc_count = len(locations) if loc_count > 0: - loc_ids_new = np.invert(np.in1d(loc_id, locations)) + loc_ids_new = np.invert(np.isin(loc_id, locations)) if len(np.nonzero(loc_ids_new)[0]) == 0: # no new locations to add return None From 698add837a5a53c08b994afa6fa722389edf4277 Mon Sep 17 00:00:00 2001 From: Wolfgang Preimesberger Date: Tue, 8 Oct 2024 11:36:54 +0200 Subject: [PATCH 2/2] Update changelog# --- CHANGELOG.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3052424..e67bace 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,12 @@ Changelog ========= +Version 0.5.1 +============= + +- Fixed a bug where global attrs were not updated when appending data +- Fixed some numpy warnings + Version 0.5.0 =============