diff --git a/setup.py b/setup.py index 03783606..3ae6b630 100644 --- a/setup.py +++ b/setup.py @@ -12,18 +12,18 @@ # TODO: Move requirements to requirements.txt requirements = ['numpy>=1.10', - 'toolz', # dask installation failing without this - 'cytoolz', # dask installation failing without this + 'toolz', # dask installation failing without this + 'cytoolz', # dask installation failing without this 'dask>=0.10', 'h5py>=2.6.0', 'matplotlib>=2.0.0', 'distributed>=2.0.0' 'psutil', 'six', - 'ipyfilechooser', + 'ipyfilechooser>=0.0.6', 'joblib>=0.11.0', 'ipywidgets>=5.2.2', - 'ipython>=5.1.0,<6;python_version<"3.3"', # IPython 6.0+ does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2 + 'ipython>=5.1.0,<6;python_version<"3.3"', # IPython 6.0+ does not support Python < 3.5 'ipython>=6.0;python_version>="3.3"', # Beginning with IPython 6.0, Python 3.3 and above is required. ] diff --git a/sidpy/__version__.py b/sidpy/__version__.py index 7d34128f..d0019586 100644 --- a/sidpy/__version__.py +++ b/sidpy/__version__.py @@ -1,2 +1,2 @@ -version = '0.0.6' -time = '2021-09-19 16:08:00' +version = '0.0.7' +time = '2021-10-22 16:08:00' diff --git a/sidpy/hdf/hdf_utils.py b/sidpy/hdf/hdf_utils.py index 5221d6f0..d05c4438 100644 --- a/sidpy/hdf/hdf_utils.py +++ b/sidpy/hdf/hdf_utils.py @@ -438,13 +438,15 @@ def write_simple_attrs(h5_obj, attrs, force_to_str=True, verbose=False): try: h5_obj.attrs[key] = clean_val except Exception as excp: - if force_to_str: - warn('Casting attribute value: {} of type: {} to str' - ''.format(val, type(val))) - h5_obj.attrs[key] = str(val) - else: - raise excp('Could not write attribute value: {} of type: {}' + if verbose: + if force_to_str: + warn('Casting attribute value: {} of type: {} to str' ''.format(val, type(val))) + h5_obj.attrs[key] = str(val) + else: + raise excp('Could not write attribute value: {} of type: {}' + ''.format(val, type(val))) + if verbose: print('Wrote all (simple) attributes to {}: {}\n' ''.format(type(h5_obj), h5_obj.name.split('/')[-1])) diff --git a/sidpy/io/interface_utils.py b/sidpy/io/interface_utils.py index a52b0d4c..81789f34 100644 --- a/sidpy/io/interface_utils.py +++ b/sidpy/io/interface_utils.py @@ -10,6 +10,7 @@ from __future__ import division, print_function, absolute_import, unicode_literals import os import sys +import warnings import ipyfilechooser if sys.version_info.major == 3: @@ -19,8 +20,9 @@ class open_file_dialog(ipyfilechooser.FileChooser): def __init__(self, directory='.'): - super().__init__(directory) self._use_dir_icons = True + super().__init__(directory) + def _apply_selection(self): @@ -72,7 +74,7 @@ def _set_form_values(self, path: str, filename: str) -> None: dircontent_real_names = ipyfilechooser.utils.get_dir_contents( path, show_hidden=self._show_hidden, - prepend_icons=False, + dir_icon_append=False, show_only_dirs=self._show_only_dirs, filter_pattern=self._filter_pattern ) @@ -81,7 +83,7 @@ def _set_form_values(self, path: str, filename: str) -> None: dircontent_display_names = ipyfilechooser.utils.get_dir_contents( path, show_hidden=self._show_hidden, - prepend_icons=self._use_dir_icons, + dir_icon_append=self._use_dir_icons, show_only_dirs=self._show_only_dirs, filter_pattern=self._filter_pattern ) @@ -403,6 +405,7 @@ def progress_bar(title='Progress', start=0, stop=100): >>> progress.setValue(count) """ # Check whether QT is available + warnings.warn("progress_bar() is deprecated; use tqdm package instead", warnings.DeprecationWarning) try: from PyQt5 import QtGui, QtWidgets, QtCore except ImportError: diff --git a/tests/hdf/test_dtype_utils.py b/tests/hdf/test_dtype_utils.py index d353efed..df04b5ff 100644 --- a/tests/hdf/test_dtype_utils.py +++ b/tests/hdf/test_dtype_utils.py @@ -56,12 +56,11 @@ def setUp(self): 1j * np.random.random(size=num_elems), dtype=np.complex64) h5_f.flush() return - + def tearDown(self): os.remove(file_path) - class TestStackRealToComplex(unittest.TestCase): def test_single(self): @@ -592,7 +591,7 @@ class TestValidateDtype(unittest.TestCase): def test_valid(self): struct_dtype = np.dtype({'names': ['r', 'g', 'b'], - 'formats': [np.float32, np.uint16, np.float64]}) + 'formats': [np.float32, np.uint16, np.float64]}) for dtype in [np.float32, np.float16, np.complex, np.complex64, np.uint8, np.int16, struct_dtype]: self.assertTrue(dtype_utils.validate_dtype(dtype)) diff --git a/tests/hdf/test_hdf_utils.py b/tests/hdf/test_hdf_utils.py index 87950b89..abaa59f2 100644 --- a/tests/hdf/test_hdf_utils.py +++ b/tests/hdf/test_hdf_utils.py @@ -231,15 +231,15 @@ class TestGetH5ObjRefs(TestHDFUtilsBase): def test_many(self): with h5py.File(data_utils.std_beps_path, mode='r') as h5_f: h5_obj_refs = [h5_f, - 4.123, - np.arange(6), - h5_f['/Raw_Measurement/Position_Indices'], - h5_f['/Raw_Measurement/source_main-Fitter_000'], - h5_f['/Raw_Measurement/source_main-Fitter_000/Spectroscopic_Indices'], - h5_f['/Raw_Measurement/Spectroscopic_Values']] + 4.123, + np.arange(6), + h5_f['/Raw_Measurement/Position_Indices'], + h5_f['/Raw_Measurement/source_main-Fitter_000'], + h5_f['/Raw_Measurement/source_main-Fitter_000/Spectroscopic_Indices'], + h5_f['/Raw_Measurement/Spectroscopic_Values']] chosen_objs = [h5_f['/Raw_Measurement/Position_Indices'], - h5_f['/Raw_Measurement/source_main-Fitter_000'], - h5_f['/Raw_Measurement/source_main-Fitter_000/Spectroscopic_Indices']] + h5_f['/Raw_Measurement/source_main-Fitter_000'], + h5_f['/Raw_Measurement/source_main-Fitter_000/Spectroscopic_Indices']] target_ref_names = ['Position_Indices', 'source_main-Fitter_000', 'Spectroscopic_Indices'] @@ -250,12 +250,12 @@ def test_many(self): def test_single(self): with h5py.File(data_utils.std_beps_path, mode='r') as h5_f: h5_obj_refs = [h5_f, - 4.123, - np.arange(6), - h5_f['/Raw_Measurement/Position_Indices'], - h5_f['/Raw_Measurement/source_main-Fitter_000'], - h5_f['/Raw_Measurement/source_main-Fitter_000/Spectroscopic_Indices'], - h5_f['/Raw_Measurement/Spectroscopic_Values']] + 4.123, + np.arange(6), + h5_f['/Raw_Measurement/Position_Indices'], + h5_f['/Raw_Measurement/source_main-Fitter_000'], + h5_f['/Raw_Measurement/source_main-Fitter_000/Spectroscopic_Indices'], + h5_f['/Raw_Measurement/Spectroscopic_Values']] chosen_objs = [h5_f['/Raw_Measurement/Position_Indices']] target_ref_names = ['Position_Indices'] @@ -324,7 +324,7 @@ def test_invalid_val_type_in_dict(self): data_utils.delete_existing_file(file_path) with h5py.File(file_path, mode='w') as h5_f: h5_group = h5_f.create_group('Blah') - #with self.assertRaises(TypeError): + # with self.assertRaises(TypeError): # hdf_utils.write_simple_attrs(h5_group, {'att_1': [{'a': 'b'}]}) os.remove(file_path) @@ -405,10 +405,10 @@ def test_nested_attrs(self): attrs = {'att_1': 'string_val', 'att_2': {'attr_3': [1, 2, 3.14, 4], 'att_4': ['s', 'tr', 'str_3']}, - 'att_5': {'att_6': 4}, + 'att_5': {'att_6': 4}, } - # with self.assertRaises(ValueError): - # hdf_utils.write_simple_attrs(h5_group, attrs) + # with self.assertRaises(ValueError): + # hdf_utils.write_simple_attrs(h5_group, attrs) os.remove(file_path) @@ -670,7 +670,7 @@ def test_file(self): data_utils.delete_existing_file(file_path) with h5py.File(file_path, mode='w') as h5_f: hdf_utils.write_book_keeping_attrs(h5_f) - data_utils.verify_book_keeping_attrs (self, h5_f) + data_utils.verify_book_keeping_attrs(self, h5_f) os.remove(file_path) def test_group(self): @@ -679,7 +679,7 @@ def test_group(self): with h5py.File(file_path, mode='w') as h5_f: h5_g = h5_f.create_group('group') hdf_utils.write_book_keeping_attrs(h5_g) - data_utils.verify_book_keeping_attrs (self, h5_g) + data_utils.verify_book_keeping_attrs(self, h5_g) os.remove(file_path) def test_dset(self): @@ -688,7 +688,7 @@ def test_dset(self): with h5py.File(file_path, mode='w') as h5_f: h5_dset = h5_f.create_dataset('dset', data=[1, 2, 3]) hdf_utils.write_book_keeping_attrs(h5_dset) - data_utils.verify_book_keeping_attrs (self, h5_dset) + data_utils.verify_book_keeping_attrs(self, h5_dset) os.remove(file_path) def test_invalid(self): @@ -1136,6 +1136,7 @@ def test_existing_dset_same_name_diff_data(self): exist_dset_diff_data_shape=False, exist_dset_diff_data=True, exist_grp_inst_dset=False) + """ def test_linking_main_plus_other_dsets(self): file_path = 'check_and_link_ancillary.h5' diff --git a/tests/io/__init__.py b/tests/io/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/io/test_interface_utils.py b/tests/io/test_interface_utils.py new file mode 100644 index 00000000..467e6d73 --- /dev/null +++ b/tests/io/test_interface_utils.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Oct 22 2021 + +@author: Gerd Duscher +""" + +from __future__ import division, print_function, unicode_literals, absolute_import +import unittest +import sys + +sys.path.append("../../sidpy/") +from sidpy.io import interface_utils + + +class TestInterface(unittest.TestCase): + + def test_open_file_dialog(self): + file_widget = interface_utils.open_file_dialog() + print(file_widget._use_dir_icons) + self.assertTrue(file_widget.selected is None)