diff --git a/examples/mf4_demo.py b/examples/mf4_demo.py index ea9525a22..5c0c489b0 100644 --- a/examples/mf4_demo.py +++ b/examples/mf4_demo.py @@ -152,7 +152,7 @@ ] sig = Signal( - np.core.records.fromarrays(samples, dtype=np.dtype(types)), + np.rec.fromarrays(samples, dtype=np.dtype(types)), t, name="Channel_lookup_with_axis", unit="A", @@ -166,7 +166,7 @@ types = [("Channel_lookup_with_default_axis", "(2, 3) N ("", f"a{record_size - byte_size - byte_offset}"), ] - vals = fromstring(data, dtype=dtype(types)) + vals = np.rec.fromstring(data, dtype=dtype(types)) vals = vals["vals"] @@ -1576,7 +1583,7 @@ def append( new_gp.sorted = True try: - samples = fromarrays(new_fields, dtype=new_types) + samples = np.rec.fromarrays(new_fields, dtype=new_types) block = samples.tobytes() except: struct_fields = [] @@ -1986,7 +1993,7 @@ def append( new_gp.sorted = True - samples = fromarrays(new_fields, dtype=new_types) + samples = np.rec.fromarrays(new_fields, dtype=new_types) block = samples.tobytes() @@ -2037,7 +2044,7 @@ def append( gp.sorted = True if signals: - samples = fromarrays(fields, dtype=types) + samples = np.rec.fromarrays(fields, dtype=types) else: samples = array([]) @@ -2293,7 +2300,7 @@ def _append_dataframe( gp.sorted = True if df.shape[0]: - samples = fromarrays(fields, dtype=types) + samples = np.rec.fromarrays(fields, dtype=types) else: samples = array([]) @@ -2479,7 +2486,7 @@ def extend(self, index: int, signals: list[tuple[NDArray[Any], None]]) -> None: # data block new_types = dtype(new_types) - samples = fromarrays(new_fields, dtype=new_types) + samples = np.rec.fromarrays(new_fields, dtype=new_types) samples = samples.tobytes() record_size = new_gp.channel_group.samples_byte_nr @@ -2534,7 +2541,7 @@ def extend(self, index: int, signals: list[tuple[NDArray[Any], None]]) -> None: # data block types = dtype(types) - samples = fromarrays(fields, dtype=types) + samples = np.rec.fromarrays(fields, dtype=types) samples = samples.tobytes() if cycles_nr: @@ -2935,7 +2942,7 @@ def get( arrays.append(sig.samples) types.append((sig.name, sig.samples.dtype)) - vals = fromarrays(arrays, dtype=types) + vals = np.rec.fromarrays(arrays, dtype=types) elif dep.dependency_type >= v23c.DEPENDENCY_TYPE_NDIM: shape = [] @@ -2971,7 +2978,7 @@ def get( types = [(channel.name, vals.dtype, record_shape)] types = dtype(types) - vals = fromarrays(arrays, dtype=types) + vals = np.rec.fromarrays(arrays, dtype=types) if not samples_only or raster: timestamps = self.get_master( diff --git a/src/asammdf/blocks/mdf_v4.py b/src/asammdf/blocks/mdf_v4.py index 856e64db8..9003dd996 100644 --- a/src/asammdf/blocks/mdf_v4.py +++ b/src/asammdf/blocks/mdf_v4.py @@ -65,8 +65,14 @@ where, zeros, ) -from numpy.core.defchararray import decode, encode -from numpy.core.records import fromarrays, fromstring + +try: + decode = np.strings.decode + encode = np.strings.encode +except: + decode = np.char.decode + encode = np.char.encode + from numpy.typing import NDArray from pandas import DataFrame @@ -2919,7 +2925,7 @@ def append( types_ = [("o", uint32), ("s", sig_dtype, sig_shape[1:])] - data = fromarrays(values, dtype=types_) + data = np.rec.fromarrays(values, dtype=types_) data_size = len(data) * data.itemsize if data_size: @@ -3226,7 +3232,7 @@ def append( vals.append(signal.samples[field] + (signal.samples["day_of_week"] << 4)) else: vals.append(signal.samples[field]) - vals = fromarrays(vals).tobytes() + vals = np.rec.fromarrays(vals).tobytes() if not vals.flags["C_CONTIGUOUS"]: vals = np.ascontiguousarray(vals) @@ -3580,7 +3586,7 @@ def append( types_ = [("o", uint32), ("s", sig_dtype)] - data = fromarrays(values, dtype=types_) + data = np.rec.fromarrays(values, dtype=types_) data_size = len(data) * data.itemsize if data_size: @@ -4152,7 +4158,7 @@ def _append_column_oriented( vals.append(signal.samples[field] + (signal.samples["day_of_week"] << 4)) else: vals.append(signal.samples[field]) - samples = fromarrays(vals) + samples = np.rec.fromarrays(vals) types.append((name, "V7")) gp.single_channel_dtype = dtype("V7") @@ -4468,7 +4474,7 @@ def _append_column_oriented( types_ = [("o", uint32), ("s", sig_dtype)] - data = fromarrays(values, dtype=types_) + data = np.rec.fromarrays(values, dtype=types_) data_size = len(data) * data.itemsize if data_size: @@ -4806,7 +4812,7 @@ def _append_dataframe( types_ = [("", uint32), ("", sig.dtype)] - data = fromarrays(values, dtype=types_) + data = np.rec.fromarrays(values, dtype=types_) data_size = len(data) * data.itemsize if data_size: @@ -4894,7 +4900,7 @@ def _append_dataframe( gp.sorted = True if df.shape[0]: - samples = fromarrays(fields, dtype=types) + samples = np.rec.fromarrays(fields, dtype=types) else: samples = array([]) @@ -5856,7 +5862,7 @@ def extend(self, index: int, signals: list[tuple[NDArray[Any], NDArray[Any] | No vals = [] for field in ("ms", "min", "hour", "day", "month", "year"): vals.append(signal[field]) - vals = fromarrays(vals).tobytes() + vals = np.rec.fromarrays(vals).tobytes() fields.append((vals, 7)) @@ -5972,7 +5978,7 @@ def extend(self, index: int, signals: list[tuple[NDArray[Any], NDArray[Any] | No types_ = [("", uint32), ("", signal.dtype)] - values = fromarrays(values, dtype=types_) + values = np.rec.fromarrays(values, dtype=types_) stream.seek(0, 2) addr = stream.tell() @@ -6157,7 +6163,7 @@ def _extend_column_oriented(self, index: int, signals: list[tuple[NDArray[Any], vals = [] for field in ("ms", "min", "hour", "day", "month", "year"): vals.append(signal[field]) - samples = fromarrays(vals) + samples = np.rec.fromarrays(vals) elif sig_type == v4c.SIGNAL_TYPE_STRUCTURE_COMPOSITION: samples = signal @@ -6174,7 +6180,7 @@ def _extend_column_oriented(self, index: int, signals: list[tuple[NDArray[Any], types_ = [("", uint32), ("", signal.dtype)] - values = fromarrays(values, dtype=types_) + values = np.rec.fromarrays(values, dtype=types_) addr = tell() block_size = len(values) * values.itemsize @@ -7059,7 +7065,7 @@ def _get_structure( types = [(name_, arr.dtype, arr.shape[1:]) for name_, arr in zip(names, arrays)] types = dtype(types) - vals = fromarrays(arrays, dtype=types) + vals = np.rec.fromarrays(arrays, dtype=types) if master_is_required: if count > 1: @@ -7351,7 +7357,7 @@ def _get_array( dtype_pair = (axisname, axis_values.dtype, shape) types.append(dtype_pair) - vals = fromarrays(arrays, dtype(types)) + vals = np.rec.fromarrays(arrays, dtype(types)) if master_is_required: timestamps.append(self.get_master(gp_nr, fragment, one_piece=True)) @@ -7904,7 +7910,7 @@ def _get_scalar( "summer_time", "day_of_week", ] - vals = fromarrays(arrays, names=names) + vals = np.rec.fromarrays(arrays, names=names) # CANopen time elif data_type == v4c.DATA_TYPE_CANOPEN_TIME: @@ -7959,7 +7965,7 @@ def _get_not_byte_aligned_data(self, data: bytes, group: Group, ch_nr: int) -> N ("", f"a{record_size - byte_size - byte_offset}"), ] - vals = fromstring(data, dtype=dtype(types)) + vals = np.rec.fromstring(data, dtype=dtype(types)) vals = vals["vals"] @@ -10350,7 +10356,7 @@ def _sort( cols = param lines = dtblock_raw_size // cols - nd = fromstring(new_data[: lines * cols], dtype=uint8) + nd = np.rec.fromstring(new_data[: lines * cols], dtype=uint8) nd = nd.reshape((cols, lines)) new_data = nd.T.ravel().tobytes() + new_data[lines * cols :] diff --git a/src/asammdf/gui/widgets/tabular.py b/src/asammdf/gui/widgets/tabular.py index b57547e82..3f2eeda42 100644 --- a/src/asammdf/gui/widgets/tabular.py +++ b/src/asammdf/gui/widgets/tabular.py @@ -3,7 +3,11 @@ import dateutil.tz import numpy as np -import numpy.core.defchararray as npchar + +try: + npchar = np.strings +except: + npchar = np.char import pandas as pd from PySide6 import QtCore, QtWidgets diff --git a/src/asammdf/gui/widgets/tabular_base.py b/src/asammdf/gui/widgets/tabular_base.py index 17951e5cc..15b41222f 100644 --- a/src/asammdf/gui/widgets/tabular_base.py +++ b/src/asammdf/gui/widgets/tabular_base.py @@ -32,7 +32,11 @@ from traceback import format_exc import numpy as np -import numpy.core.defchararray as npchar + +try: + npchar = np.strings +except: + npchar = np.char import pandas as pd import pyqtgraph.functions as fn from PySide6 import QtCore, QtGui, QtWidgets diff --git a/src/asammdf/signal.py b/src/asammdf/signal.py index 70ec91af8..022277224 100644 --- a/src/asammdf/signal.py +++ b/src/asammdf/signal.py @@ -8,7 +8,11 @@ from typing import Any import numpy as np -from numpy.core.defchararray import encode + +try: + encode = np.strings.encode +except: + encode = np.char.encode from numpy.typing import ArrayLike, DTypeLike, NDArray from .blocks import v2_v3_blocks as v3b diff --git a/test/test_mdf.py b/test/test_mdf.py index 2a67c61ec..81b4acbe8 100644 --- a/test/test_mdf.py +++ b/test/test_mdf.py @@ -164,7 +164,7 @@ def test_read_arrays(self): vals = mdf.get(f"Channel_{j}", group=i, samples_only=True)[0] target = [arr * j for arr in samples] - target = np.core.records.fromarrays(target, dtype=types) + target = np.rec.fromarrays(target, dtype=types) if not np.array_equal(vals, target): equal = False raise Exception @@ -180,7 +180,7 @@ def test_read_arrays(self): vals = mdf.get(f"Channel_{j}", group=i, samples_only=True)[0] target = [samples * j] - target = np.core.records.fromarrays(target, dtype=types) + target = np.rec.fromarrays(target, dtype=types) if not np.array_equal(vals, target): equal = False raise Exception @@ -212,7 +212,7 @@ def test_read_arrays(self): vals = mdf.get(f"Channel_{j}", group=i, samples_only=True)[0] target = [arr * j for arr in samples] - target = np.core.records.fromarrays(target, dtype=types) + target = np.rec.fromarrays(target, dtype=types) if not np.array_equal(vals, target): equal = False print(target) @@ -539,7 +539,7 @@ def test_cut_arrays(self): vals = mdf.get(f"Channel_{j}", group=i, samples_only=True)[0] target = [arr * j for arr in samples] - target = np.core.records.fromarrays(target, dtype=types) + target = np.rec.fromarrays(target, dtype=types) if not np.array_equal(vals, target): equal = False print( @@ -564,7 +564,7 @@ def test_cut_arrays(self): vals = mdf.get(f"Channel_{j}", group=i, samples_only=True)[0] target = [samples * j] - target = np.core.records.fromarrays(target, dtype=types) + target = np.rec.fromarrays(target, dtype=types) if not np.array_equal(vals, target): equal = False raise Exception @@ -596,7 +596,7 @@ def test_cut_arrays(self): vals = mdf.get(f"Channel_{j}", group=i, samples_only=True)[0] target = [arr * j for arr in samples] - target = np.core.records.fromarrays(target, dtype=types) + target = np.rec.fromarrays(target, dtype=types) if not np.array_equal(vals, target): equal = False raise Exception diff --git a/test/test_mdf4.py b/test/test_mdf4.py index 9993efce2..8161d7126 100644 --- a/test/test_mdf4.py +++ b/test/test_mdf4.py @@ -130,7 +130,7 @@ def test_channel_with_boolean_array(self): samples = [np.ones((5, 2), dtype=np.uint8)] types = [("boolean_array_channel", "(2, )