Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for numpy 2 #336

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading