Skip to content

Commit

Permalink
deprecating old function
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Sep 15, 2022
1 parent 3f39ef1 commit e67cc76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
32 changes: 3 additions & 29 deletions GooseHDF5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ def copy(
:param source_root: Path prefix for all ``source_datasets``.
:param recursive: If the source is a group, copy all objects within that group recursively.
:param skip: Skip datasets that are not present in source.
:param expand_soft: Copy the underlying data of a link, or copy as link with the same path.
:param expand_soft:
If True: create a copy of the source dataset.
If False: create a link (with identical path as in the source).
"""

if len(source_datasets) == 0:
Expand Down Expand Up @@ -679,34 +681,6 @@ def copy(
)


def copydatasets(
source: h5py.File,
dest: h5py.File,
source_datasets: list[str],
dest_datasets: list[str] = None,
root: str = None,
):
"""
Copy datasets from one HDF5-archive ``source`` to another HDF5-archive ``dest``.
The datasets can be renamed by specifying a list of ``dest_datasets``
(whose entries should correspond to the ``source_datasets``).
If the source is a Group object,
by default all objects within that group will be copied recursively.
In addition, a ``root`` (path prefix) for the destination datasets name can be specified.
:param source: The source HDF5-archive.
:param dest: The destination HDF5-archive.
:param source_datasets: List of dataset-paths in ``source``.
:param dest_datasets: List of dataset-paths in ``dest``, defaults to ``source_datasets``.
:param root: Path prefix for all ``dest_datasets``.
"""

warnings.warn("copydatasets() is deprecated, use copy().", category=DeprecationWarning)

return copy(source, dest, source_datasets, dest_datasets, root)


def isnumeric(a):
"""
Returns ``True`` is an array contains numeric values.
Expand Down
7 changes: 2 additions & 5 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Examples
********

Copy part of a file
====================
===================

Suppose that you want to copy all but some dataset from a file.
In that case you can use
Expand All @@ -16,7 +16,4 @@ Consider the following example.
.. literalinclude:: examples/copy_modify-selection.py
:language: python

.. note::

The copy functions from *h5py* copy attributes as well.
By extension also :py:meth:`GooseHDF5.copy` copies all attributes.
The last line includes an example on how to verify if a set of datasets is indeed the same.
18 changes: 10 additions & 8 deletions docs/examples/copy_modify-selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@

import GooseHDF5 as g5

with h5py.File("foo.h5", "w") as data:
with h5py.File("foo.h5", "w") as file:

data["/a"] = np.arange(5)
data["/b/c"] = np.arange(5)
data["/d/e/f"] = np.arange(5)
file["/a"] = np.arange(5)
file["/b/c"] = np.arange(5)
file["/d/e/f"] = np.arange(5)

with h5py.File("foo.h5", "r") as data:
with h5py.File("foo.h5", "r") as file:

paths = list(g5.getdatasets(data))
paths = list(g5.getdatasets(file))
paths.remove("/d/e/f")

with h5py.File("bar.h5", "w") as ret:
g5.copy(data, ret, paths)
ret["/d/e/f"] = data["/d/e/f"][...] * 2
g5.copy(file, ret, paths)
ret["/d/e/f"] = file["/d/e/f"][...] * 2

print(g5.compare(file, ret, paths))

0 comments on commit e67cc76

Please sign in to comment.