Skip to content

Commit

Permalink
Fix tests for numpy 2
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve committed Sep 16, 2024
1 parent 0c1b930 commit d2c4c59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nptdms/export/hdf_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ def _hdf_attr_value(value):
""" Convert a value into a format suitable for an HDF attribute
"""
if isinstance(value, np.datetime64):
return np.string_(np.datetime_as_string(value, unit='us', timezone='UTC'))
return np.bytes_(np.datetime_as_string(value, unit='us', timezone='UTC'))
return value
18 changes: 18 additions & 0 deletions nptdms/test/test_thermocouples.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,21 @@ def _test_voltage_to_temperature(reference_thermocouple, thermocouple, voltage,
reference_temperature = reference_thermocouple.inverse_CmV(voltage, Tref=0.0)
temperature = thermocouple.mv_to_celsius(voltage)
assert abs(temperature - reference_temperature) < max_error + 1.0E-6


@pytest.fixture(autouse=True)
def patch_thermocouples_reference(monkeypatch):
"""
thermocouples_reference creates an array with np.array(T, copy=False)
which causes an error on numpy 2 for non-array inputs.
We can't workaround this by only passing in numpy arrays as there are also
internal uses that cause this error, so monkeypatch to fix this.
"""
_prev_call = thermocouples_reference.function_types.Polynomial_Gaussian_Piecewise_Function.__call__

def _new_call(self, t, *args, **kwargs):
t = np.asarray(t)
return _prev_call(self, t, *args, **kwargs)

monkeypatch.setattr(
thermocouples_reference.function_types.Polynomial_Gaussian_Piecewise_Function, "__call__", _new_call)

0 comments on commit d2c4c59

Please sign in to comment.