Skip to content

Commit

Permalink
Merge pull request #281 from ericpre/numpy2.0
Browse files Browse the repository at this point in the history
Numpy 2
  • Loading branch information
jlaehne authored Jun 24, 2024
2 parents fe16741 + 6d2c9db commit de98a8e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]_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
Expand Down
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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,<2.0.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"]
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion rsciio/dens/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions rsciio/renishaw/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion rsciio/semper/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/281.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for numpy 2 in Renishaw, Semper and Dens reader.

0 comments on commit de98a8e

Please sign in to comment.