Skip to content

Commit

Permalink
Fix numpy2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSegerblomRex committed Jun 28, 2024
1 parent e4e8a58 commit b32c926
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
23 changes: 15 additions & 8 deletions libtiff/libtiff_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@

__all__ = ['libtiff', 'TIFF']

SCTYPES = {
"float": [np.float16, np.float32, np.float64],
"uint": [np.uint8, np.uint16, np.uint32, np.uint64, np.bool_],
"int": [np.int8, np.int16, np.int32, np.int64],
"complex": [np.complex64, np.complex128],
}

cwd = os.getcwd()
try:
os.chdir(os.path.dirname(__file__))
Expand Down Expand Up @@ -729,13 +736,13 @@ def write_image(self, arr, compression=None, write_rgb=False):
compression = self._fix_compression(compression)

arr = np.ascontiguousarray(arr)
if arr.dtype in np.sctypes['float']:
if arr.dtype in SCTYPES["float"]:
sample_format = SAMPLEFORMAT_IEEEFP
elif arr.dtype in np.sctypes['uint'] + [np.bool_]:
elif arr.dtype in SCTYPES["uint"]:
sample_format = SAMPLEFORMAT_UINT
elif arr.dtype in np.sctypes['int']:
elif arr.dtype in SCTYPES["int"]:
sample_format = SAMPLEFORMAT_INT
elif arr.dtype in np.sctypes['complex']:
elif arr.dtype in SCTYPES["complex"]:
sample_format = SAMPLEFORMAT_COMPLEXIEEEFP
else:
raise NotImplementedError(repr(arr.dtype))
Expand Down Expand Up @@ -816,13 +823,13 @@ def write_tiles(self, arr, tile_width=None, tile_height=None,
compression=None, write_rgb=False):
compression = self._fix_compression(compression)

if arr.dtype in np.sctypes['float']:
if arr.dtype in SCTYPES["float"]:
sample_format = SAMPLEFORMAT_IEEEFP
elif arr.dtype in np.sctypes['uint'] + [np.bool_]:
elif arr.dtype in SCTYPES["uint"]:
sample_format = SAMPLEFORMAT_UINT
elif arr.dtype in np.sctypes['int']:
elif arr.dtype in SCTYPES["int"]:
sample_format = SAMPLEFORMAT_INT
elif arr.dtype in np.sctypes['complex']:
elif arr.dtype in SCTYPES["complex"]:
sample_format = SAMPLEFORMAT_COMPLEXIEEEFP
else:
raise NotImplementedError(repr(arr.dtype))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=60", "wheel", "setuptools_scm[toml]>=8.0", 'oldest-supported-numpy']
requires = ["setuptools>=60", "wheel", "setuptools_scm[toml]>=8.0", "numpy>=2.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def setup_package():
"Intended Audience :: Science/Research",
"License :: OSI Approved",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
"Operating System :: Microsoft :: Windows",
Expand All @@ -42,8 +42,8 @@ def setup_package():
description='PyLibTiff: a Python tiff library.',
long_description=long_description,
long_description_content_type='text/markdown',
install_requires=['numpy>=1.13.3'],
python_requires='>=3.8',
install_requires=['numpy>=1.24.5'],
python_requires='>=3.9',
extras_require={
'bitarray': ['bitarray'],
},
Expand Down

0 comments on commit b32c926

Please sign in to comment.