Skip to content

Commit

Permalink
pre-commit autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Apr 18, 2023
1 parent 597cca4 commit 4b3046a
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 88 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
args: [--safe, --quiet, --line-length=100]
Expand All @@ -12,7 +12,7 @@ repos:
- id: check-yaml
- id: debug-statements
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.5.0
rev: v2.8.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2']
Expand Down Expand Up @@ -40,7 +40,7 @@ repos:
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/tdegeus/conda_envfile
rev: v0.4.1
rev: v0.4.2
hooks:
- id: conda_envfile_parse
files: environment.yaml
29 changes: 0 additions & 29 deletions GooseHDF5/__init__.py
Expand Up @@ -40,7 +40,6 @@ class ExtendableList:
"""

def __init__(self, file: h5py.File, key: str, dtype, chunk: int = 1000, **kwargs):

assert key not in file

self.chunk = chunk
Expand Down Expand Up @@ -74,7 +73,6 @@ def flush(self):
self.dset.parent.file.flush()

def __add__(self, data: ArrayLike):

if isinstance(data, list):
self.data += data
self._flush()
Expand All @@ -86,7 +84,6 @@ def __add__(self, data: ArrayLike):
return self

def append(self, data: int | float):

self.data.append(data)
self._flush()

Expand Down Expand Up @@ -131,7 +128,6 @@ def _dict_iterategroups(data: dict, root: str = "/"):
"""

for key in data.keys():

item = data[key]
path = join(root, key)

Expand Down Expand Up @@ -383,9 +379,7 @@ def _getpaths(file, root):
# ---------------------------------------------

def iterator(g, prefix):

for key in g.keys():

item = g[key]
path = join(prefix, key)

Expand Down Expand Up @@ -413,9 +407,7 @@ def _getpaths_maxdepth(file, root, max_depth, fold_symbol):
# ---------------------------------------------

def iterator(g, prefix, max_depth):

for key in g.keys():

item = g[key]
path = join(prefix, key)

Expand Down Expand Up @@ -452,9 +444,7 @@ def _getpaths_fold(file, root, fold, fold_symbol):
# ---------------------------------------------

def iterator(g, prefix, fold):

for key in g.keys():

item = g[key]
path = join(prefix, key)

Expand Down Expand Up @@ -489,9 +479,7 @@ def _getpaths_fold_maxdepth(file, root, fold, max_depth, fold_symbol):
# ---------------------------------------------

def iterator(g, prefix, fold, max_depth):

for key in g.keys():

item = g[key]
path = join(prefix, key)

Expand Down Expand Up @@ -555,7 +543,6 @@ def verify(file, datasets, error=False):
ret = []

for path in datasets:

try:
file[path][...]
except: # noqa: E722
Expand Down Expand Up @@ -772,7 +759,6 @@ def isnumeric(a):


def _equal_value(a, b, close):

import numpy as np

if type(a) == str:
Expand Down Expand Up @@ -825,9 +811,7 @@ def _equal_value(a, b, close):


def _equal(a, b, attrs, matching_dtype, shallow, close):

if attrs:

for key in a.attrs:
if key not in b.attrs:
return False
Expand Down Expand Up @@ -978,7 +962,6 @@ def _compare_paths(
paths_b = list(getdatasets(b, max_depth=max_depth, fold=fold, fold_symbol=symbol))

if fold:

fold = [join(f, symbol, root=True) for f in fold]

for path in paths_a:
Expand Down Expand Up @@ -1089,7 +1072,6 @@ def _(
list_folded: bool = False,
close: bool = False,
) -> dict[list]:

ret = {"<-": [], "->": [], "!=": [], "==": []}
paths_a, paths_b, fold_a, fold_b = _compare_paths(
a, b, paths_a, paths_b, False if only_datasets else attrs, max_depth, fold
Expand Down Expand Up @@ -1134,7 +1116,6 @@ def _(
list_folded: bool = False,
close: bool = False,
) -> dict[list]:

with h5py.File(a, "r") as a_file, h5py.File(b, "r") as b_file:
return compare(
a_file,
Expand Down Expand Up @@ -1301,7 +1282,6 @@ def copy_dataset(source, dest, paths, compress=False, double_to_float=False):
paths = list(paths)

for path in paths:

data = source[path][...]

if data.size == 1 or not compress or not isnumeric(data):
Expand All @@ -1318,7 +1298,6 @@ def copy_dataset(source, dest, paths, compress=False, double_to_float=False):


def _linktype2str(source: h5py.File | h5py.Group, path: str) -> str:

dset = source.get(path, getlink=True)

if isinstance(dset, h5py.SoftLink):
Expand Down Expand Up @@ -1415,7 +1394,6 @@ def print_attribute(source, paths: list[str]):

for path in paths:
if path in source:

data = source[path]

print(f'"{path}"')
Expand Down Expand Up @@ -1472,7 +1450,6 @@ def G5print(args: list[str]):
np.set_printoptions(threshold=sys.maxsize)

with h5py.File(args.source, "r") as source:

if len(args.dataset) == 0:
print_header = True
datasets = list(
Expand Down Expand Up @@ -1500,7 +1477,6 @@ def G5print(args: list[str]):
return 1

for i, dataset in enumerate(datasets):

data = source[dataset]

if args.info:
Expand Down Expand Up @@ -1574,7 +1550,6 @@ def G5list(args: list[str]):
raise OSError(f'"{args.source}" does not exist')

with h5py.File(args.source, "r") as source:

if args.layer is not None:
paths = sorted(join(args.layer, i, root=True) for i in source[args.layer])
else:
Expand Down Expand Up @@ -1684,7 +1659,6 @@ def G5compare(args: list[str]):
)

def def_row(arg, colors):

if colors == "none":
if arg[1] == "!=":
return arg
Expand Down Expand Up @@ -1780,17 +1754,14 @@ def G5modify(args: list[str]):
raise OSError(f'"{args.file}" does not exist')

with h5py.File(args.file, "r+") as file:

if args.path not in file:

shape = [len(args.values)]
if args.shape:
shape = [int(i) for i in args.shape.split(",")]
assert np.prod(shape) == len(args.values)
file.create_dataset(args.path, shape=shape, dtype=args.dtype)

else:

assert len(args.values) == file[args.path].size

file[args.path][:] = np.array(args.values).reshape(file[args.path].shape)
Expand Down
4 changes: 0 additions & 4 deletions GooseHDF5/cli/G5check.py
Expand Up @@ -42,15 +42,13 @@ def check_isfile(fname):


def read(filename, check):

with h5py.File(filename, "r") as source:
paths = getdatapaths(source)
if check:
verify(source, paths, error=True)


def main():

try:

class Parser(argparse.ArgumentParser):
Expand All @@ -67,11 +65,9 @@ def print_help(self):
read(args.source, not args.basic)

except Exception as e:

print(e)
return 1


if __name__ == "__main__":

main()
4 changes: 0 additions & 4 deletions GooseHDF5/cli/G5repack.py
Expand Up @@ -46,7 +46,6 @@ def check_isfile(fname):


def main():

try:

class Parser(argparse.ArgumentParser):
Expand All @@ -63,7 +62,6 @@ def print_help(self):
tempname = next(tempfile._get_candidate_names())

for filename in args.source:

print(filename)

check_isfile(filename)
Expand All @@ -75,11 +73,9 @@ def print_help(self):
os.replace(tempname, filename)

except Exception as e:

print(e)
return 1


if __name__ == "__main__":

main()
4 changes: 0 additions & 4 deletions GooseHDF5/cli/G5repair.py
Expand Up @@ -47,7 +47,6 @@ def check_isfile(fname):


def main():

try:

class Parser(argparse.ArgumentParser):
Expand All @@ -68,18 +67,15 @@ def print_help(self):
sys.exit(1)

with h5py.File(args.source, "r") as source:

paths = verify(source, getdatapaths(source))

with h5py.File(args.destination, "w") as dest:
copy(source, dest, paths)

except Exception as e:

print(e)
return 1


if __name__ == "__main__":

main()
2 changes: 0 additions & 2 deletions docs/examples/copy_modify-selection.py
Expand Up @@ -4,13 +4,11 @@
import GooseHDF5 as g5

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

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 file:

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

Expand Down
1 change: 0 additions & 1 deletion tests/cli/G5compare.py
Expand Up @@ -13,7 +13,6 @@ def run(cmd):

with h5py.File("a.hdf5", "w") as source:
with h5py.File("b.hdf5", "w") as other:

# NumPy array

a = np.random.random(25)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_cli.py
Expand Up @@ -22,13 +22,11 @@ class MyTests(unittest.TestCase):

@classmethod
def setUpClass(self):

if not os.path.isdir(dirname):
os.makedirs(dirname)

@classmethod
def tearDownClass(self):

shutil.rmtree(dirname)

def test_G5list(self):
Expand Down Expand Up @@ -109,5 +107,4 @@ def test_G5modify_depth(self):


if __name__ == "__main__":

unittest.main()

0 comments on commit 4b3046a

Please sign in to comment.