diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 35f44cc4..90ce7679 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/tests_numpy1.yml b/.github/workflows/tests_numpy1.yml new file mode 100644 index 00000000..c4d39f79 --- /dev/null +++ b/.github/workflows/tests_numpy1.yml @@ -0,0 +1,54 @@ +name: 'Tests for Numpy < 2' + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + + - name: Install linux dependencies + run: | + trap 'echo -e "$ $BASH_COMMAND"' DEBUG + sudo apt-get update + sudo apt-get install libsndfile1 sox + + - name: Install python dependencies + run: | + trap 'echo -e "$ $BASH_COMMAND"' DEBUG + python -m pip install --upgrade pip + pip install 'numpy<2' scipy Cython + pip install flake8 pytest pytest-cov codecov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install setuptools==57.5.0 # downgrade setuptools so pycallgraph can be installed (necessary for python >= 3.9) + pip install --editable .[all] + pip install git+https://github.com/fgnt/pb_bss.git#egg=pb_bss[all] + + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax error or undefined names + #flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + #flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + - name: Test with pytest + run: | + pytest -v + - name: Codecov + run: | + codecov diff --git a/paderbox/array/interval/core.py b/paderbox/array/interval/core.py index 06d75bf8..d4f8150d 100644 --- a/paderbox/array/interval/core.py +++ b/paderbox/array/interval/core.py @@ -846,10 +846,10 @@ def __getitem__(self, item): def sum(self, axis=None, out=None): """ >>> a = ArrayInterval([True, True, False, False]) - >>> np.sum(a) + >>> print(np.sum(a)) 2 >>> a = ArrayInterval([True, False, False, True]) - >>> np.sum(a) + >>> print(np.sum(a)) 2 >>> np.sum(zeros(10)) 0 diff --git a/paderbox/array/sparse.py b/paderbox/array/sparse.py index 1adc4e64..7db58200 100644 --- a/paderbox/array/sparse.py +++ b/paderbox/array/sparse.py @@ -320,8 +320,8 @@ class SparseArray: dtype is inferred from segments: >>> a.dtype dtype('float64') - >>> a.pad_value, type(a.pad_value) - (0.0, ) + >>> print(a.pad_value, type(a.pad_value)) + 0.0 Can't add segments with differing dtypes >>> a[:3] = np.ones(3, dtype=np.float32) @@ -446,11 +446,11 @@ def pad_value(self): >>> a = SparseArray(10) >>> a.pad_value # is None >>> a[:5] = np.arange(5) - >>> a.pad_value + >>> print(a.pad_value) 0 - >>> zeros(10).pad_value + >>> print(zeros(10).pad_value) 0.0 - >>> full(10, 42).pad_value + >>> print(full(10, 42).pad_value) 42.0 """ # _pad_value must be an array, otherwise pt.data.batch.example_to_device @@ -905,8 +905,8 @@ def __getitem__(self, item): >>> a[15:] = np.arange(5, dtype=np.float64) + 1 # Integer getitem - >>> a[0], a[9], a[10], a[14], a[15], a[18], a[-1] - (1.0, 1.0, 0.0, 0.0, 1.0, 4.0, 5.0) + >>> print(a[0], a[9], a[10], a[14], a[15], a[18], a[-1]) + 1.0 1.0 0.0 0.0 1.0 4.0 5.0 >>> a[21] Traceback (most recent call last): ... @@ -957,16 +957,16 @@ def __getitem__(self, item): # Unknown time length >>> a = zeros((None,)) - >>> a[10] + >>> print(a[10]) 0.0 >>> a[:10], np.asarray(a[:10]) (SparseArray(shape=(10,)), array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)) >>> a[:5] = 1 >>> np.asarray(a[2:7]) array([1., 1., 1., 0., 0.], dtype=float32) - >>> a[0] + >>> print(a[0]) 1.0 - >>> a[10] + >>> print(a[10]) 0.0 >>> a.persist_shape() (5,) diff --git a/paderbox/io/hdf5.py b/paderbox/io/hdf5.py index 55463d70..fbcb28f1 100644 --- a/paderbox/io/hdf5.py +++ b/paderbox/io/hdf5.py @@ -4,7 +4,7 @@ import numpy as np -from distutils.version import LooseVersion +from packaging.version import parse as _parse __all__ = ['dump_hdf5', 'update_hdf5', 'load_hdf5'] @@ -120,9 +120,9 @@ def update_hdf5( >>> update_hdf5('peter', file, '/name', allow_overwrite=True) >>> pprint(load_hdf5(file)) {'name': 'peter'} - >>> update_hdf5({'name': 1}, file, '/', allow_overwrite=True) + >>> update_hdf5({'name': 'Alice'}, file, '/', allow_overwrite=True) >>> pprint(load_hdf5(file)) - {'name': 1} + {'name': 'Alice'} """ if not isinstance(obj, dict): path_split = path.rsplit('/', 1) @@ -179,8 +179,9 @@ def load_hdf5(filename, path='/'): ... } >>> dump_hdf5(ex, file, True) >>> ex_load = load_hdf5(file) - >>> from pprint import pprint - >>> ex_load['fav_tensors']['kronecker2d'][0, 0] + >>> # from pprint import pprint + >>> from paderbox.utils.pretty import pprint + >>> print(ex_load['fav_tensors']['kronecker2d'][0, 0]) 1.0 >>> pprint(ex_load) {'age': 24, @@ -193,7 +194,7 @@ def load_hdf5(filename, path='/'): 'fav_tensors': {'kronecker2d': array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), - 'levi_civita3d': array([[[ 0, 0, 0], + 'levi_civita3d': array([[[ 0, 0, 0], [ 0, 0, 1], [ 0, -1, 0]], @@ -403,7 +404,7 @@ def ckeck_exists(): h5file[cur_path] = item # This query is necessary since h5py changed string # handling after version 3.0.0 to dumping strings as bytes - if LooseVersion(h5py.__version__) >= '3.0.0': + if _parse(h5py.__version__) >= _parse('3.0.0'): test_item = item.encode('utf-8') else: test_item = item @@ -477,12 +478,13 @@ def __load_dict_from_hdf5__(cls, filename, path='/'): @classmethod def __recursively_load_dict_contents_from_group__(cls, h5file, path): """ + >>> from paderbox.utils.pretty import pprint >>> from paderbox.io.cache_dir import get_cache_dir >>> file = get_cache_dir() / 'tmp.hdf5' >>> ex = {'key': [1, 2, 3]} >>> dump_hdf5(ex, file, True) >>> ex_load = load_hdf5(file) - >>> ex_load + >>> pprint(ex_load) {'key': [1, 2, 3]} """ import h5py @@ -508,7 +510,7 @@ def __recursively_load_dict_contents_from_group__(cls, h5file, path): # This query is necessary since h5py changed string # handling after version 3.0.0 to dumping strings as bytes - if LooseVersion(h5py.__version__) >= '3.0.0': + if _parse(h5py.__version__) >= _parse('3.0.0'): ans[key] = ans[key].decode() if isinstance(ans[key], str) and ans[key] == 'None': ans[key] = None diff --git a/paderbox/io/json_module.py b/paderbox/io/json_module.py index c5a187cd..ccbde931 100644 --- a/paderbox/io/json_module.py +++ b/paderbox/io/json_module.py @@ -39,21 +39,24 @@ class SummaryEncoder(Encoder): >>> example = dict(a=np.random.uniform(size=(3, 4))) >>> print(json.dumps(example, cls=SummaryEncoder, indent=2)) { - "a": "ndarray: shape (3, 4), dtype float64" + "a": "array(shape=(3, 4), dtype=float64)" } alternative: - >>> np.set_string_function(lambda a: f'array(shape={a.shape}, dtype={a.dtype})') - >>> example + >>> from paderbox.utils.pretty import pprint + >>> # np.set_string_function(lambda a: f'array(shape={a.shape}, dtype={a.dtype})') # removed in numpy 2.0 without replacement, see https://github.com/napari/napari/issues/6752 + >>> pprint(example, max_array_length=0) {'a': array(shape=(3, 4), dtype=float64)} - >>> np.set_string_function(None) # needed for pytest. np.set_string_function is not properly reseted. """ def default(self, obj): if isinstance(obj, np.ndarray): - return 'ndarray: shape {}, dtype {}'.format(obj.shape, obj.dtype) + return f'array(shape={obj.shape}, dtype={obj.dtype})' else: - return super().default(obj) + try: + return super().default(obj) + except TypeError: + return str(obj) def dumps_json( diff --git a/paderbox/io/new_subdir.py b/paderbox/io/new_subdir.py index cd0c10be..919ef039 100644 --- a/paderbox/io/new_subdir.py +++ b/paderbox/io/new_subdir.py @@ -112,7 +112,7 @@ def get_new_subdir( # ToDo: Make this working. # Will fail when calling os.listdir else: - basedir.mkdir(parents=True) + basedir.mkdir(parents=True, exist_ok=True) if Path('/net') in basedir.parents: # If nt filesystem, assert not in /net/home @@ -121,13 +121,13 @@ def get_new_subdir( prefix_ = f'{prefix}_' if prefix else '' _suffix = f'_{suffix}' if suffix else '' - for i in range(200): + for i in range(1000): if id_naming == 'index': if prefix is None and suffix is None: dir_nrs = [ - int(d) - for d in os.listdir(str(basedir)) - if (basedir / d).is_dir() and d.isdigit() + int(d.name) + for d in os.scandir(str(basedir)) + if d.is_dir() and d.name.isdigit() ] _id = max(dir_nrs + [0]) + 1 else: @@ -138,11 +138,11 @@ def remove_pre_suf(d): ) dir_nrs = [ - int(remove_pre_suf(d)) - for d in os.listdir(str(basedir)) - if (basedir / d).is_dir() - if fnmatch.fnmatch(d, f'{prefix_}*{_suffix}') - if remove_pre_suf(d).isdigit() + int(remove_pre_suf(d.name)) + for d in os.scandir(str(basedir)) + if d.is_dir() + if fnmatch.fnmatch(d.name, f'{prefix_}*{_suffix}') + if remove_pre_suf(d.name).isdigit() ] dir_nrs += [0] _id = max(dir_nrs) + 1 @@ -177,7 +177,7 @@ def remove_pre_suf(d): return simu_dir except FileExistsError: # Catch race conditions - if i > 100: + if i > 200: # After some tries, # expect that something other went wrong raise @@ -253,8 +253,8 @@ class NameGenerator: >>> ng = NameGenerator() >>> ng() 'nice_tomato_fox' - >>> ng.possibilities() # With 22 million a collision is unlikely - 22188920 + >>> f'{ng.possibilities():_}' # With 22 million a collision is unlikely + '22_188_920' >>> ng = NameGenerator(['adjectives', 'animals']) >>> ng() 'regional_prawn' @@ -321,8 +321,8 @@ def cli( Args: basedir: - id_naming: e.g. 'index', 'time', 'adjective_color_animal' - mkdir: + id_naming: e.g. 'index', 'time', 'adjective_color_animal' (default 'index') + mkdir: (default True) prefix: suffix: consider_mpi: diff --git a/paderbox/math/directional.py b/paderbox/math/directional.py index d66ff6f6..64e0fce8 100644 --- a/paderbox/math/directional.py +++ b/paderbox/math/directional.py @@ -6,9 +6,9 @@ def wrap(angle): Beware! Every possible method treats the corner case -pi differently. - >>> wrap(-np.pi) + >>> print(wrap(-np.pi)) -3.141592653589793 - >>> wrap(np.pi) + >>> print(wrap(np.pi)) 3.141592653589793 :param angle: Angle as numpy array in radian @@ -22,9 +22,9 @@ def wrap_with_modulo(angle): Beware! Every possible method treats the corner case -pi differently. - >>> wrap_with_modulo(-np.pi) + >>> print(wrap_with_modulo(-np.pi)) -3.141592653589793 - >>> wrap_with_modulo(np.pi) + >>> print(wrap_with_modulo(np.pi)) -3.141592653589793 :param angle: Angle as numpy array in radian @@ -38,9 +38,9 @@ def wrap_with_angle_exp(angle): Beware! Every possible method treats the corner case -pi differently. - >>> wrap_with_angle_exp(-np.pi) + >>> print(wrap_with_angle_exp(-np.pi)) -3.141592653589793 - >>> wrap_with_angle_exp(np.pi) + >>> print(wrap_with_angle_exp(np.pi)) 3.141592653589793 :param angle: Angle as numpy array in radian @@ -54,9 +54,9 @@ def wrap_with_arctan2(angle): Beware! Every possible method treats the corner case -pi differently. - >>> wrap_with_arctan2(-np.pi) + >>> print(wrap_with_arctan2(-np.pi)) -3.141592653589793 - >>> wrap_with_arctan2(np.pi) + >>> print(wrap_with_arctan2(np.pi)) 3.141592653589793 :param angle: Angle as numpy array in radian @@ -70,9 +70,9 @@ def wrap_with_arctan_tan(angle): Beware! Every possible method treats the corner case -pi differently. - >>> wrap_with_arctan_tan(-np.pi) + >>> print(wrap_with_arctan_tan(-np.pi)) -3.141592653589793 - >>> wrap_with_arctan_tan(np.pi) + >>> print(wrap_with_arctan_tan(np.pi)) 3.141592653589793 :param angle: Angle as numpy array in radian @@ -84,9 +84,9 @@ def wrap_with_arctan_tan(angle): def minus(angle1, angle2): """ Calculate angular difference. - >>> minus(0, np.pi) + >>> print(minus(0, np.pi)) -3.141592653589793 - >>> minus(0, -np.pi) + >>> print(minus(0, -np.pi)) 3.141592653589793 :param angle1: Minuend @@ -99,9 +99,9 @@ def minus(angle1, angle2): def minus_with_wrap(angle1, angle2): """ Calculate angular difference. - >>> minus_with_wrap(0, np.pi) + >>> print(minus_with_wrap(0, np.pi)) -3.141592653589793 - >>> minus_with_wrap(0, -np.pi) + >>> print(minus_with_wrap(0, -np.pi)) 3.141592653589793 :param angle1: Minuend @@ -114,9 +114,9 @@ def minus_with_wrap(angle1, angle2): def minus_with_angle_exp(angle1, angle2): """ Calculate angular difference. - >>> minus_with_angle_exp(0, np.pi) + >>> print(minus_with_angle_exp(0, np.pi)) -3.141592653589793 - >>> minus_with_angle_exp(0, -np.pi) + >>> print(minus_with_angle_exp(0, -np.pi)) 3.141592653589793 :param angle1: Minuend @@ -149,13 +149,13 @@ def rad_to_deg(a): def direction_vector_to_angle(vector): """ Takes a 2D direction vector and creates a single direction angle. - >>> direction_vector_to_angle(np.asarray([[0], [0]])) + >>> print(direction_vector_to_angle(np.asarray([[0], [0]]))) 0.0 - >>> direction_vector_to_angle(np.asarray([[1], [1]])) + >>> print(direction_vector_to_angle(np.asarray([[1], [1]]))) 0.7853981633974483 - >>> direction_vector_to_angle(np.asarray([[0], [1]])) + >>> print(direction_vector_to_angle(np.asarray([[0], [1]]))) 1.5707963267948966 """ assert vector.shape == (2, 1) diff --git a/paderbox/math/solve.py b/paderbox/math/solve.py index 1a673d6f..befffa5a 100644 --- a/paderbox/math/solve.py +++ b/paderbox/math/solve.py @@ -101,7 +101,7 @@ def stable_solve(A, B, rcond=-1): assert A.shape[-1] == B.shape[-2], (A.shape, B.shape) try: return np.linalg.solve(A, B) - except np.linalg.linalg.LinAlgError: + except np.linalg.LinAlgError: shape_A, shape_B = A.shape, B.shape assert shape_A[:-2] == shape_A[:-2] working_shape_A = [functools.reduce(operator.mul, [1, *shape_A[:-2]]), @@ -116,6 +116,6 @@ def stable_solve(A, B, rcond=-1): # lstsq is much slower, use it only when necessary try: C[i] = np.linalg.solve(A[i], B[i]) - except np.linalg.linalg.LinAlgError: + except np.linalg.LinAlgError: C[i], *_ = np.linalg.lstsq(A[i], B[i], rcond=rcond) return C.reshape(*shape_B) diff --git a/paderbox/transform/module_fbank.py b/paderbox/transform/module_fbank.py index ae24e2a7..afa5b629 100644 --- a/paderbox/transform/module_fbank.py +++ b/paderbox/transform/module_fbank.py @@ -409,8 +409,8 @@ def hz_warping( 4000, warp_factor=.9, boundary_frequency_ratio=.75,\ highest_frequency=highest_frequency,\ ) - >>> f_warped, f_warped.shape - (3600.0, ()) + >>> print(f_warped, f_warped.shape) + 3600.0 () >>> f_warped = hz_warping(\ 8000, warp_factor=.9, boundary_frequency_ratio=np.array([.75, 1.]),\ highest_frequency=highest_frequency,\ diff --git a/paderbox/transform/module_stft.py b/paderbox/transform/module_stft.py index f82629c0..9d4a2416 100644 --- a/paderbox/transform/module_stft.py +++ b/paderbox/transform/module_stft.py @@ -66,7 +66,7 @@ def stft( window_length = size # Pad with zeros to have enough samples for the window function to fade. - assert fading in [None, True, False, 'full', 'half'], fading + assert fading in [None, True, False, 'full', 'half'], (fading, type(fading)) if fading not in [False, None]: pad_width = np.zeros((time_signal.ndim, 2), dtype=int) if fading == 'half': @@ -539,7 +539,7 @@ def _biorthogonal_window_brute_force(analysis_window, shift, >>> print(synthesis_window) [-1.12717575e-17 2.76153346e-01 8.12215724e-01 2.76153346e-01] >>> mult = analysis_window * synthesis_window - >>> sum(mult) + >>> print(sum(mult)) 1.0000000000000002 """ size = len(analysis_window) diff --git a/paderbox/utils/pandas_utils.py b/paderbox/utils/pandas_utils.py index ff5f925b..eb03cc5d 100644 --- a/paderbox/utils/pandas_utils.py +++ b/paderbox/utils/pandas_utils.py @@ -1,6 +1,7 @@ import fnmatch from IPython.display import display +import numpy as np import pandas as pd @@ -168,8 +169,8 @@ def _unique_elements(pd_series): dtype: object >>> _unique_elements(s) [1, (1,), [1], {1}, {5: {6: 7}}] - >>> _unique_elements([1, 2, 3, 1, 3]) - [1, 2, 3] + >>> np.array(_unique_elements([1, 2, 3, 1, 3])) + array([1, 2, 3]) """ try: @@ -285,6 +286,8 @@ def squeeze_df( 1 {1: 1} """ + from paderbox.utils.pretty import pretty + if query: df_tmp = py_query(df, query=query, use_pd_query=use_pd_query).copy() else: @@ -302,10 +305,10 @@ def squeeze_df( if len(unique) == 1: drop.append(k) if verbose: - print(k, unique) + print(k, pretty(unique)) elif len(unique) <= max_set_len: if verbose: - print(k, unique) + print(k, pretty(unique)) if drop_glob: if isinstance(drop_glob, str): @@ -388,15 +391,16 @@ def summary_df(df, query=None, max_unique_values=3): b [2, 4, ...] """ + from paderbox.utils.pretty import pretty if query: df = py_query(df, query=query) for k, v in list(df.items()): unique = _unique_elements(v) if len(unique) <= max_unique_values: - print(k, unique) + print(k, pretty(unique)) else: class Dots: def __repr__(self): return '...' - print(k, unique[:max_unique_values] + [Dots()]) + print(k, pretty(unique[:max_unique_values] + [Dots()])) diff --git a/paderbox/utils/pretty.py b/paderbox/utils/pretty.py index b577245e..af13c3ca 100644 --- a/paderbox/utils/pretty.py +++ b/paderbox/utils/pretty.py @@ -58,6 +58,7 @@ def __init__( *args, max_array_length, np_suppress_small, + nep51, **kwargs, ): super().__init__(*args, **kwargs) @@ -92,7 +93,20 @@ def _ipy_pprint_tensor(obj, p, cycle): f')' ) + if nep51: + # https://numpy.org/neps/nep-0051-scalar-representation.html + def _ipy_pprint_ndnumber(obj, p, cycle): + # This is numpy 2.X style + p.text(f'np.{obj.__class__.__name__}({obj})') + else: + def _ipy_pprint_ndnumber(obj, p, cycle): + # This is numpy 1.X style + p.text(str(obj)) + self.type_pprinters[np.ndarray] = _ipy_pprint_ndarray + # self.type_pprinters[np.number] = _ipy_pprint_ndnumber # doesn't work, __repr__ has priority over __mro__ + for dtype in [np.int64, np.float64, np.complex128]: + self.type_pprinters[dtype] = _ipy_pprint_ndnumber self.deferred_pprinters[('torch', 'Tensor')] = _ipy_pprint_tensor self.type_pprinters[type({}.keys())] = \ IPython.lib.pretty._seq_pprinter_factory('dict_keys(', ')') @@ -191,6 +205,7 @@ def pprint( max_seq_length=IPython.lib.pretty.MAX_SEQ_LENGTH, max_array_length=50, np_suppress_small=True, + nep51=False, ): """ Copy of IPython.lib.pretty.pprint. @@ -199,6 +214,9 @@ def pprint( - Support multiple objects (Causes bad readable error in original) - Support list/tuple for max_seq_length, where max(depth, len(max_seq_length)-1) is used as index. + - By default disable NEP 51 that was introduced in numpy 2. + Pre NEP 51: Numpy scalars are printed like Python scalars + Since NEP 51: Numpy scalars are printed as e.g. np.int64(1) >>> pprint([np.array([1.]), np.array([1.]*100)]) @@ -232,6 +250,10 @@ def pprint( dict_items([('aaaaaaaaaa', 1000000), ('bbbbbbbbbb', 2000000)]) + >>> pprint(np.sum([1])) + 1 + >>> pprint(np.sum([1]), nep51=True) + np.int64(1) """ @@ -240,6 +262,7 @@ def pprint( max_seq_length=max_seq_length, max_array_length=max_array_length, np_suppress_small=np_suppress_small, + nep51=nep51, ) if len(objs): @@ -261,6 +284,7 @@ def pretty( max_seq_length=IPython.lib.pretty.MAX_SEQ_LENGTH, max_array_length=50, np_suppress_small=True, + nep51=False, ): """ Copy of IPython.lib.pretty.pretty. @@ -276,6 +300,7 @@ def pretty( max_seq_length=max_seq_length, max_array_length=max_array_length, np_suppress_small=np_suppress_small, + nep51=nep51, ) if len(objs): printer.pretty((obj, *objs)) diff --git a/tests/io_tests/test_hdf5.py b/tests/io_tests/test_hdf5.py index 42857db9..9fd641c1 100644 --- a/tests/io_tests/test_hdf5.py +++ b/tests/io_tests/test_hdf5.py @@ -4,16 +4,26 @@ import paderbox.testing as tc import numpy as np from paderbox.io import dump_hdf5, load_hdf5 +import packaging.version +# numpy default integer type on Windows is int32 for numpy v1.x +# In numpy v2.x it was changed to int64 to match unix and mac. +_default_np_int = ( + np.int32 + if os.name == 'nt' + and packaging.version.parse(np.__version__) < packaging.version.parse('2') + else + np.int64 +) class TestHdf5: @pytest.mark.parametrize("name,data,expect", [ - ('int', {'key': 1}, np.int32(1) if os.name == 'nt' else np.int64(1)), # numpy default integer type on Windows is always int32. + ('int', {'key': 1}, _default_np_int(1)), ('float', {'key': 1.1}, np.float64(1.1)), ('complex', {'key': 1.1j}, np.complex128(1.1j)), ('str', {'key': 'bla'}, 'bla'), ('none', {'key': None}, None), - ('np int', {'key': int(1)}, np.int32(1) if os.name == 'nt' else np.int64(1)), + ('np int', {'key': int(1)}, _default_np_int(1)), ('np float32', {'key': np.float32(1.1)}, np.float32(1.1)), ('np float64', {'key': np.float64(1.1)}, np.float64(1.1)), ('np complex64', {'key': np.complex64(1.1j)}, np.complex64(1.1j)), @@ -23,7 +33,7 @@ class TestHdf5: ('tuple', {'key': (1, 2, 3)}, np.array([1, 2, 3])), # ('set', {'key': {1, 2, 3}}, {1, 2, 3}), ('array', {'key': np.array([1, 2, 3])}, np.array([1, 2, 3])), - ('np nan', {'key': np.NaN}, np.float64(np.NaN)), + ('np nan', {'key': np.nan}, np.float64(np.nan)), ('np inf', {'key': np.inf}, np.float64(np.inf)), ('np array nan inf', {'key': np.asarray([0, 1, np.nan, np.inf])}, np.asarray([0, 1, np.nan, np.inf])), diff --git a/tests/io_tests/test_pickle.py b/tests/io_tests/test_pickle.py index da774b4c..aff0d9a9 100644 --- a/tests/io_tests/test_pickle.py +++ b/tests/io_tests/test_pickle.py @@ -22,7 +22,7 @@ class TestPickle: ('tuple', {'key': (1, 2, 3)}, (1, 2, 3)), ('set', {'key': {1, 2, 3}}, {1, 2, 3}), ('array', {'key': np.array([1, 2, 3])}, np.array([1, 2, 3])), - ('np nan', {'key': np.NaN}, np.NaN), + ('np nan', {'key': np.nan}, np.nan), ('np inf', {'key': np.inf}, np.inf), ('np array nan inf', {'key': np.asarray([0, 1, np.nan, np.inf])}, np.asarray([0, 1, np.nan, np.inf])), @@ -40,4 +40,4 @@ def test_dump_load(self,name,data,expect): assert type(expect) is type(data_load['key']), \ (type(expect), type(data_load['key']), expect, data_load['key']) - tc.assert_equal(expect, data_load['key']) \ No newline at end of file + tc.assert_equal(expect, data_load['key'])