From 0f0b25d278f23c869feb9e7148d64c87328c1b59 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Thu, 20 Jun 2024 23:15:55 +0100 Subject: [PATCH 1/5] Fix reading some numeric with numpy 2.0 --- pyproject.toml | 2 +- rsciio/renishaw/_api.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2fdb10fc0..bf36e9c3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ dependencies = [ "dask[array]>=2021.3.1", "python-dateutil", - "numpy>=1.20.0,<2.0.0", + "numpy>=1.20.0", "pint>=0.8", # python-box API changed on major release # and compatibility needs to be checked diff --git a/rsciio/renishaw/_api.py b/rsciio/renishaw/_api.py index 6da969300..f59cdafc7 100644 --- a/rsciio/renishaw/_api.py +++ b/rsciio/renishaw/_api.py @@ -922,9 +922,7 @@ def _parse_ORGN(self, header_orgn_count): for _ in range(origin_count): ax_tmp_dict = {} ## ignore first bit of dtype read (sometimes 0, sometimes 1 in testfiles) - dtype = DataType( - self.__read_numeric("uint32", convert=False) & ~(0b1 << 31) - ).name + dtype = DataType(self.__read_numeric("uint32") & ~(0b1 << 31)).name ax_tmp_dict["units"] = str(UnitType(self.__read_numeric("uint32"))) ax_tmp_dict["annotation"] = self.__read_utf8(0x10) ax_tmp_dict["data"] = self._set_data_for_ORGN(dtype) From 85c11d9026faf746c352617896655df6c79d5316 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 23 Jun 2024 10:32:38 +0100 Subject: [PATCH 2/5] Update CI to test with numpy 2 --- .github/workflows/tests.yml | 23 ++++++++++++++++++----- pyproject.toml | 12 +++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bea9f2dad..6afa18ba7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -118,18 +118,31 @@ jobs: pip install git+https://github.com/hyperspy/hyperspy.git pip install git+https://github.com/hyperspy/exspy.git - - name: Install latest python-box - # When installing hyperspy, python-box 6 is installed (rosettasciio pinning) - # Remove when rosettasciio >0.4.0 is released - if: ${{ ! contains(matrix.LABEL, 'oldest') }} + - name: Install pint and python-mrcz dev + # for numpy 2.0 support for python >= 3.9 + # https://github.com/em-MRCZ/python-mrcz/pull/15 + # https://github.com/hgrecco/pint/issues/1974 + if: ${{ ! contains(matrix.LABEL, 'oldest') && matrix.PYTHON_VERSION != '3.8' }} run: | - pip install --upgrade python-box + pip install git+https://github.com/ericpre/python-mrcz.git@numpy2.0_and_deprecation_fixes + pip install git+https://github.com/hgrecco/pint - name: Install shell: bash run: | pip install --upgrade -e .'${{ env.PIP_SELECTOR }}' + - name: Uninstall pyUSID + # remove when pyUSID supports numpy 2 + if: ${{ ! contains(matrix.LABEL, 'oldest') && matrix.PYTHON_VERSION != '3.8' }} + run: | + pip uninstall -y pyUSID + + - name: Install numpy 2.0 + if: ${{ ! contains(matrix.LABEL, 'oldest') && matrix.PYTHON_VERSION != '3.8' }} + run: | + pip install numpy==2 + - name: Pip list run: | pip list diff --git a/pyproject.toml b/pyproject.toml index bf36e9c3e..aa3f7da43 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,13 +23,13 @@ classifiers = [ "Topic :: Software Development :: Libraries", ] dependencies = [ - "dask[array]>=2021.3.1", + "dask[array] >=2021.3.1", "python-dateutil", - "numpy>=1.20.0", - "pint>=0.8", + "numpy >=1.20", + "pint >=0.8", # python-box API changed on major release # and compatibility needs to be checked - "python-box>=6,<8", + "python-box >=6,<8", "pyyaml", ] dynamic = ["version"] @@ -97,9 +97,7 @@ mrcz = ["blosc>=1.5", "mrcz>=0.3.6"] scalebar_export = ["matplotlib-scalebar", "matplotlib>=3.5"] speed = ["numba>=0.52"] tiff = ["tifffile>=2022.7.28", "imagecodecs"] -# Add sidpy dependency and pinning as workaround to fix pyUSID import -# Remove sidpy dependency once https://github.com/pycroscopy/pyUSID/issues/85 is fixed. -usid = ["pyUSID", "sidpy<=0.12.0"] +usid = ["pyUSID>=0.0.11"] zspy = ["zarr", "msgpack"] tests = [ "filelock", From 529e2c5df5d73142c2c22e2e8f4b184a7ca22114 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 23 Jun 2024 10:55:46 +0100 Subject: [PATCH 3/5] Add support for numpy 2.0 in dens reader --- rsciio/dens/_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rsciio/dens/_api.py b/rsciio/dens/_api.py index 94ab766eb..136b70e6e 100644 --- a/rsciio/dens/_api.py +++ b/rsciio/dens/_api.py @@ -27,7 +27,10 @@ def _cnv_time(timestr): try: - t = datetime.strptime(timestr.decode(), "%H:%M:%S.%f") + if not isinstance(timestr, str): + # for numpy < 2.0 + timestr = timestr.decode() + t = datetime.strptime(timestr, "%H:%M:%S.%f") dt = t - datetime(t.year, t.month, t.day) r = float(dt.seconds) + float(dt.microseconds) * 1e-6 except ValueError: From 7d9d2b2bc86667fdee27f64261737c21eccce302 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 23 Jun 2024 11:27:35 +0100 Subject: [PATCH 4/5] Add support for numpy 2 in semper reader --- rsciio/semper/_api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rsciio/semper/_api.py b/rsciio/semper/_api.py index 540ebfa80..af64cd9a1 100644 --- a/rsciio/semper/_api.py +++ b/rsciio/semper/_api.py @@ -218,7 +218,11 @@ def _read_label(cls, unf_file): assert label["SEMPER"] == "Semper" # Process dimensions: for key in ["NCOL", "NROW", "NLAY", "ICCOLN", "ICROWN", "ICLAYN"]: - value = 256**2 * label.pop(key + "H") + 256 * label[key][0] + label[key][1] + value = ( + 256**2 * np.int32(label.pop(key + "H")) + + 256 * label[key][0] + + label[key][1] + ) label[key] = value # Process date: date = "{}-{}-{} {}:{}:{}".format(label["DATE"][0] + 1900, *label["DATE"][1:]) From 6d2c9dbe61987fccb91d12f272f90bf7529b0d57 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 23 Jun 2024 12:22:37 +0100 Subject: [PATCH 5/5] Add changelog entry --- upcoming_changes/281.maintenance.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 upcoming_changes/281.maintenance.rst diff --git a/upcoming_changes/281.maintenance.rst b/upcoming_changes/281.maintenance.rst new file mode 100644 index 000000000..2e0389835 --- /dev/null +++ b/upcoming_changes/281.maintenance.rst @@ -0,0 +1 @@ +Add support for numpy 2 in Renishaw, Semper and Dens reader.