Skip to content

Commit

Permalink
Fix string handling in h5py 3.0 (#977)
Browse files Browse the repository at this point in the history
* Fix string handling in h5py 3.0

* Add runtimeerror to valueerror catches

* Explicit tuple

* More runtimeerrors when it used to raise a different exception
  • Loading branch information
ksunden committed Nov 4, 2020
1 parent 2bd35b0 commit ae0c99e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
- Return min and max when file is read only
- try/except the os.close call for tempfile (may already be gone in SWMR mode)
- data objects retain units of individual axes when copied
- h5py 3.0 string handling

## [3.3.1]

Expand Down
8 changes: 4 additions & 4 deletions WrightTools/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def f(dataset, s):
arr = dataset[s]
try:
amin = np.nanargmax(arr)
except ValueError:
except (ValueError, RuntimeError):
amin = 0
idx = np.unravel_index(amin, arr.shape)
val = arr[idx]
Expand All @@ -215,7 +215,7 @@ def f(dataset, s):
arr = dataset[s]
try:
amin = np.nanargmin(arr)
except ValueError:
except (ValueError, RuntimeError):
amin = 0
idx = np.unravel_index(amin, arr.shape)
val = arr[idx]
Expand Down Expand Up @@ -378,7 +378,7 @@ def f(dataset, s):
max_ = np.nanmax(list(self.chunkwise(f).values()))
try:
self.attrs["max"] = max_
except OSError:
except (OSError, RuntimeError):
# Cannot write file, just return, can't cache
return max_

Expand All @@ -395,7 +395,7 @@ def f(dataset, s):
min_ = np.nanmin(list(self.chunkwise(f).values()))
try:
self.attrs["min"] = min_
except OSError:
except (OSError, RuntimeError):
# Cannot write file, just return, can't cache
return min_

Expand Down
6 changes: 4 additions & 2 deletions WrightTools/data/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def __init__(self, *args, **kwargs):
Group.__init__(self, *args, **kwargs)
# populate axes, constants from attrs string
for identifier in self.attrs.get("axes", []):
identifier = identifier.decode()
if hasattr(identifier, "decode"):
identifier = identifier.decode()
expression, units = identifier.split("{")
units = units.replace("}", "").strip()
if units == "None":
Expand All @@ -59,7 +60,8 @@ def __init__(self, *args, **kwargs):
axis = Axis(self, expression, units)
self._axes.append(axis)
for identifier in self.attrs.get("constants", []):
identifier = identifier.decode()
if hasattr(identifier, "decode"):
identifier = identifier.decode()
expression, units = identifier.split("{")
units = units.replace("}", "").strip()
if units == "None":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def read(fname):
package_data=extra_files,
python_requires=">=3.6",
install_requires=[
"h5py<3",
"h5py",
"imageio",
"matplotlib>=3.3.0",
"numexpr",
Expand Down

0 comments on commit ae0c99e

Please sign in to comment.