From 98ddc3b61018c439b4cf7ade6ebb05d9fe9f4d4f Mon Sep 17 00:00:00 2001 From: Tianlu Yuan Date: Wed, 30 Nov 2016 17:05:09 -0600 Subject: [PATCH 1/6] update to pytables pt2to3 --- dashi/datasets/hdf_datasets.py | 20 ++++++++++---------- dashi/objbundleutils.py | 10 +++++----- dashi/storage.py | 18 +++++++++--------- dashi/tests/datasets_test.py | 4 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/dashi/datasets/hdf_datasets.py b/dashi/datasets/hdf_datasets.py index a66d2a9..64d62a5 100644 --- a/dashi/datasets/hdf_datasets.py +++ b/dashi/datasets/hdf_datasets.py @@ -25,9 +25,9 @@ def read_variable(h5file, path): if ":" in path: path_, column = path.split(":") - return h5file.getNode(path_).col(column) + return h5file.get_node(path_).col(column) else: - return h5file.getNode(path).read() + return h5file.get_node(path).read() ################################################################################ @@ -41,12 +41,12 @@ def hdf_toc(h5file): """ toc = [] - for node in h5file.walkNodes(classname="Table"): + for node in h5file.walk_nodes(classname="Table"): for varname in node.description._v_names: toc.append( "%s:%s" % (node._v_pathname, varname) ) for arraytype in ["Array", "EArray"]: - for node in h5file.walkNodes(classname=arraytype): + for node in h5file.walk_nodes(classname=arraytype): toc.append( node._v_pathname ) return sorted(toc) @@ -66,7 +66,7 @@ def store_earray1d(h5file, path, array, complevel=6, **kwargs): if complevel > 0: filters = tables.Filters(complevel=complevel, complib="zlib") - earr = h5file.createEArray(parent, arrname, + earr = h5file.create_earray(parent, arrname, tables.Atom.from_dtype(array.dtype), (0,), filters=filters, @@ -101,12 +101,12 @@ def _ds_toc(self): if not self.isopen: return toc - for node in self.walkNodes(classname="Table"): + for node in self.walk_nodes(classname="Table"): toc.append( node._v_pathname ) for varname in node.description._v_names: toc.append( "%s:%s" % (node._v_pathname, varname) ) - for node in self.walkNodes(classname="Array"): + for node in self.walk_nodes(classname="Array"): toc.append( node._v_pathname ) self._ds_toc_cache = sorted(toc) @@ -121,18 +121,18 @@ def _ds_write_variable(self, path, array): arrname = os.path.basename(path) self._ds_toc_cache = None if array.dtype.names is None: - earr = self.createEArray(parent, arrname, + earr = self.create_earray(parent, arrname, tables.Atom.from_dtype(array.dtype), (0,), filters=self.filters, createparents=True) earr.append(array) earr.flush() else: - tab = self.createTable(parent, arrname, array, createparents=True, filters=self.filters) + tab = self.create_table(parent, arrname, array, createparents=True, filters=self.filters) tab.flush() def _ds_remove_variable(self, path): try: - self.removeNode(path) + self.remove_node(path) self.flush() except tables.NoSuchNodeError as exc: raise ValueError("removing path %s raised a NoSuchNodeError" % path) diff --git a/dashi/objbundleutils.py b/dashi/objbundleutils.py index a29d69b..b514785 100644 --- a/dashi/objbundleutils.py +++ b/dashi/objbundleutils.py @@ -95,9 +95,9 @@ def read_hdf(h5file, selection): if isinstance(cfg, str): if ":" in cfg: path, column = cfg.split(":") - arrays[varname] = h5file.getNode(path).col(column) + arrays[varname] = h5file.get_node(path).col(column) else: - arrays[varname] = h5file.getNode(cfg).read() + arrays[varname] = h5file.get_node(cfg).read() elif callable(cfg): args = inspect.getargspec(cfg).args if args == ["file"]: @@ -112,7 +112,7 @@ def bundle2h5group(bundle, file, h5group): import tables assert isinstance(h5group, str) for key,array in bundle: - earr = file.createEArray(h5group, key, + earr = file.create_earray(h5group, key, tables.Atom.from_dtype(array.dtype), (0,), filters=tables.Filters(complevel=6, complib="zlib"), createparents=True) earr.append(array) @@ -123,7 +123,7 @@ def h5group2bundle(file, h5group): assert isinstance(h5group, str) arrays = dict() - for key in file.getNode(h5group)._v_children.keys(): - arrays[key] = file.getNode(h5group+"/"+key).read() + for key in file.get_node(h5group)._v_children.keys(): + arrays[key] = file.get_node(h5group+"/"+key).read() return bundle(**arrays) diff --git a/dashi/storage.py b/dashi/storage.py index fa4d2a1..a796cc6 100644 --- a/dashi/storage.py +++ b/dashi/storage.py @@ -28,16 +28,16 @@ def histsave(histo, path, where, name, overwrite=False, complib='blosc'): """ import tables with maybe_open_file(path, 'a') as file: - parentgroup = file.getNode(where) + parentgroup = file.get_node(where) if name in parentgroup._v_children: if not overwrite: raise ValueError("there exists already a histogram with name %s" % name) else: - file.removeNode(parentgroup, name, recursive=True) + file.remove_node(parentgroup, name, recursive=True) # create a new group and store all necessary arrays into it - group = file.createGroup(where, name) + group = file.create_group(where, name) attr = group._v_attrs attr["ndim"] = histo.ndim @@ -49,16 +49,16 @@ def histsave(histo, path, where, name, overwrite=False, complib='blosc'): def save(arr, where): filters = tables.Filters(complib=complib, complevel=9) - ca = file.createCArray(group, where, tables.Atom.from_dtype(arr.dtype), arr.shape, filters=filters) + ca = file.create_carray(group, where, tables.Atom.from_dtype(arr.dtype), arr.shape, filters=filters) ca[:] = arr save(histo._h_bincontent, "_h_bincontent") save(histo._h_squaredweights, "_h_squaredweights") - # file.createArray(group, "_h_bincontent", histo._h_bincontent) - # file.createArray(group, "_h_squaredweights", histo._h_squaredweights) + # file.create_array(group, "_h_bincontent", histo._h_bincontent) + # file.create_array(group, "_h_squaredweights", histo._h_squaredweights) for dim in range(histo.ndim): - file.createArray(group, "_h_binedges_%d" % dim, histo._h_binedges[dim]) + file.create_array(group, "_h_binedges_%d" % dim, histo._h_binedges[dim]) attr["label_%d" % dim] = histo.labels[dim] @@ -70,11 +70,11 @@ def histload(path, histgroup): the latter, the file will be opened in read-only mode and closed before the function returns histgroup : the group containing the histogram (the one created by histsave) - can be anything what file.getNode accepts, eg. a string or a Group + can be anything what file.get_node accepts, eg. a string or a Group object """ with maybe_open_file(path) as file: - group = file.getNode(histgroup) + group = file.get_node(histgroup) attr = group._v_attrs histo = None diff --git a/dashi/tests/datasets_test.py b/dashi/tests/datasets_test.py index ea7c831..21fda7a 100644 --- a/dashi/tests/datasets_test.py +++ b/dashi/tests/datasets_test.py @@ -24,8 +24,8 @@ arr["y"] = n.arange(100, 0, -1, dtype=int) fname = "%s_%d.h5" % (name,j) - f = tables.openFile(fname, "a") - f.createTable("/", "test", arr) + f = tables.open_file(fname, "a") + f.create_table("/", "test", arr) f.close() datafiles[name].append(fname) From d52d755b44242570cac2fa2a84f27d3b2d80a37a Mon Sep 17 00:00:00 2001 From: Tianlu Yuan <5412915+tianluyuan@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:19:27 -0500 Subject: [PATCH 2/6] update for python 3.10 --- dashi/odict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashi/odict.py b/dashi/odict.py index 52e3460..53befe0 100644 --- a/dashi/odict.py +++ b/dashi/odict.py @@ -1,6 +1,6 @@ -from collections import MutableMapping +from collections.abc import MutableMapping class OrderedDict(MutableMapping): """ From eb7c74a908cd423a67f39cf216846bb9b5e7c7c9 Mon Sep 17 00:00:00 2001 From: Tianlu Yuan <5412915+tianluyuan@users.noreply.github.com> Date: Mon, 10 Apr 2023 13:06:04 -0500 Subject: [PATCH 3/6] use tuple for ND slice --- dashi/histogram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashi/histogram.py b/dashi/histogram.py index f40a620..3b70564 100644 --- a/dashi/histogram.py +++ b/dashi/histogram.py @@ -244,7 +244,7 @@ def __init__(self, ndim, binedges, bincontent=None, squaredweights=None, labels= assert self._h_squaredweights.shape == tuple(datacubeshape) # present views of the non overflow bins to the outside - self._h_visiblerange = [slice(1,-1) for i in range(self.ndim)] + self._h_visiblerange = tuple(slice(1,-1) for i in range(self.ndim)) self._h_newdataavailable = True # internal trigger for the recalculation of dervived values (e.g. errors, stats,..) From 675a0fbe1cdddb71566cbc7075772457f0648001 Mon Sep 17 00:00:00 2001 From: Tianlu Yuan Date: Wed, 30 Nov 2016 17:05:09 -0600 Subject: [PATCH 4/6] update to pytables pt2to3 --- dashi/datasets/hdf_datasets.py | 16 ++++++++-------- dashi/tests/datasets_test.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dashi/datasets/hdf_datasets.py b/dashi/datasets/hdf_datasets.py index 2859252..cdd14a6 100644 --- a/dashi/datasets/hdf_datasets.py +++ b/dashi/datasets/hdf_datasets.py @@ -41,12 +41,12 @@ def hdf_toc(h5file): """ toc = [] - for node in h5file.walkNodes(classname="Table"): + for node in h5file.walk_nodes(classname="Table"): for varname in node.description._v_names: toc.append( "%s:%s" % (node._v_pathname, varname) ) for arraytype in ["Array", "EArray"]: - for node in h5file.walkNodes(classname=arraytype): + for node in h5file.walk_nodes(classname=arraytype): toc.append( node._v_pathname ) return sorted(toc) @@ -66,7 +66,7 @@ def store_earray1d(h5file, path, array, complevel=6, **kwargs): if complevel > 0: filters = tables.Filters(complevel=complevel, complib="zlib") - earr = h5file.createEArray(parent, arrname, + earr = h5file.create_earray(parent, arrname, tables.Atom.from_dtype(array.dtype), (0,), filters=filters, @@ -101,12 +101,12 @@ def _ds_toc(self): if not self.isopen: return toc - for node in self.walkNodes(classname="Table"): + for node in self.walk_nodes(classname="Table"): toc.append( node._v_pathname ) for varname in node.description._v_names: toc.append( "%s:%s" % (node._v_pathname, varname) ) - for node in self.walkNodes(classname="Array"): + for node in self.walk_nodes(classname="Array"): toc.append( node._v_pathname ) self._ds_toc_cache = sorted(toc) @@ -121,18 +121,18 @@ def _ds_write_variable(self, path, array): arrname = os.path.basename(path) self._ds_toc_cache = None if array.dtype.names is None: - earr = self.createEArray(parent, arrname, + earr = self.create_earray(parent, arrname, tables.Atom.from_dtype(array.dtype), (0,), filters=self.filters, createparents=True) earr.append(array) earr.flush() else: - tab = self.createTable(parent, arrname, array, createparents=True, filters=self.filters) + tab = self.create_table(parent, arrname, array, createparents=True, filters=self.filters) tab.flush() def _ds_remove_variable(self, path): try: - self.removeNode(path) + self.remove_node(path) self.flush() except tables.NoSuchNodeError as exc: raise ValueError("removing path %s raised a NoSuchNodeError" % path) diff --git a/dashi/tests/datasets_test.py b/dashi/tests/datasets_test.py index ea7c831..21fda7a 100644 --- a/dashi/tests/datasets_test.py +++ b/dashi/tests/datasets_test.py @@ -24,8 +24,8 @@ arr["y"] = n.arange(100, 0, -1, dtype=int) fname = "%s_%d.h5" % (name,j) - f = tables.openFile(fname, "a") - f.createTable("/", "test", arr) + f = tables.open_file(fname, "a") + f.create_table("/", "test", arr) f.close() datafiles[name].append(fname) From 3323cd04b05fe1c6b6c140c0876d508169f4b6bb Mon Sep 17 00:00:00 2001 From: Tianlu Yuan <5412915+tianluyuan@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:19:27 -0500 Subject: [PATCH 5/6] update for python 3.10 --- dashi/odict.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dashi/odict.py b/dashi/odict.py index 5d9874f..24762bd 100644 --- a/dashi/odict.py +++ b/dashi/odict.py @@ -1,4 +1,2 @@ - # Python 3 dictionaries remember insertion order OrderedDict = dict - From 38ecbe82711f0ee6e54eec8cfceb028617b875b5 Mon Sep 17 00:00:00 2001 From: Tianlu Yuan <5412915+tianluyuan@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:55:28 -0500 Subject: [PATCH 6/6] use getfullargspec --- dashi/fitting.py | 2 +- dashi/objbundleutils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dashi/fitting.py b/dashi/fitting.py index 1b1bb8e..54c6364 100644 --- a/dashi/fitting.py +++ b/dashi/fitting.py @@ -26,7 +26,7 @@ def __init__(self, callable, integral_callable=None): :params integral_callable: a function P(X < x) """ self.dfunc = callable - argspec = inspect.getargspec(callable) + argspec = inspect.getfullargspec(callable) self.func = integral_callable # initialize params with 1 which is a better starting value than zero for factors diff --git a/dashi/objbundleutils.py b/dashi/objbundleutils.py index 8dbd963..aaeaa84 100644 --- a/dashi/objbundleutils.py +++ b/dashi/objbundleutils.py @@ -68,7 +68,7 @@ def read_hdf(h5file, selection): readorder.insert(0, (varname, [] )) #print "insert", varname elif callable(cfg): - args = inspect.getargspec(cfg).args + args = inspect.getfullargspec(cfg).args if args == ["file"]: # pass h5file, calculation doesn't depend on anything readorder.insert(0, (varname, []) ) @@ -99,7 +99,7 @@ def read_hdf(h5file, selection): else: arrays[varname] = h5file.get_node(cfg).read() elif callable(cfg): - args = inspect.getargspec(cfg).args + args = inspect.getfullargspec(cfg).args if args == ["file"]: arrays[varname] = cfg(h5file) else: