Skip to content

Commit

Permalink
Merge pull request #62 from wpreimes/fix-append-mode
Browse files Browse the repository at this point in the history
Fix append mode
  • Loading branch information
wpreimes authored Oct 8, 2024
2 parents 542a90d + 698add8 commit e0d9544
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============

Expand Down
2 changes: 0 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ dependencies:
- pip:
- pygeobase
- pygeogrids
- pytest
- pytest-cov
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ exclude =

# Add here test requirements (semicolon/line-separated)
testing =
setuptools
pytest
pytest-cov

Expand Down
4 changes: 2 additions & 2 deletions src/pynetcf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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][:]

Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/pynetcf/point_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/pynetcf/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e0d9544

Please sign in to comment.