Skip to content

Commit afd5ca4

Browse files
authored
Merge branch 'main' into ipython-docs
2 parents ef8eb8d + 8e6fe11 commit afd5ca4

13 files changed

+43
-97
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pip-delete-this-directory.txt
3535

3636
# Unit test / coverage reports
3737
htmlcov/
38-
.tox/
3938
.coverage
4039
.coverage.*
4140
.cache

docs/contributing.rst

+9-5
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,12 @@ Test coverage
212212

213213
Zarr maintains 100% test coverage under the latest Python stable release (currently
214214
Python 3.8). Both unit tests and docstring doctests are included when computing
215-
coverage. Running ``tox -e py38`` will automatically run the test suite with coverage
216-
and produce a coverage report. This should be 100% before code can be accepted into the
217-
main code base.
215+
coverage. Running::
216+
217+
$ python -m pytest -v --cov=zarr --cov-config=.coveragerc zarr
218+
219+
will automatically run the test suite with coverage and produce a coverage report.
220+
This should be 100% before code can be accepted into the main code base.
218221

219222
When submitting a pull request, coverage will also be collected across all supported
220223
Python versions via the Codecov service, and will be reported back within the pull
@@ -243,9 +246,10 @@ notes (``docs/release.rst``).
243246

244247
The documentation can be built locally by running::
245248

246-
$ tox -e docs
249+
$ cd docs
250+
$ make clean; make html
247251

248-
The resulting built documentation will be available in the ``.tox/docs/tmp/html`` folder.
252+
The resulting built documentation will be available in the ``docs/_build/html`` folder.
249253

250254
Development best practices, policies and procedures
251255
---------------------------------------------------

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Contents
130130
contributing
131131
release
132132
license
133+
View homepage <https://zarr.dev/>
133134

134135
Indices and tables
135136
------------------

docs/release.rst

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Unreleased
1717
Maintenance
1818
~~~~~~~~~~~
1919

20+
* Simplify if/else statement.
21+
By :user:`Dimitri Papadopoulos Orfanos <DimitriPapadopoulos>` :issue:`1227`.
22+
2023
* Migrate to ``pyproject.toml`` and remove redundant infrastructure.
2124
By :user:`Saransh Chopra <Saransh-cpp>` :issue:`1158`.
2225

release.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
tox
21
# version=x.x.x
32
echo $version
43
git tag -a v$version -m v$version

requirements_dev_minimal.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ numcodecs==0.10.2
55
msgpack-python==0.5.6
66
setuptools-scm==7.0.5
77
# test requirements
8-
pytest==7.1.3
8+
pytest==7.2.0

requirements_dev_optional.txt

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ types-redis
1313
types-setuptools
1414
pymongo==4.3.2
1515
# optional test requirements
16-
tox==3.26.0
1716
coverage
1817
flake8==5.0.4
1918
pytest-cov==4.0.0

tox.ini

-51
This file was deleted.

zarr/convenience.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,11 @@ def __init__(self, log):
487487
elif isinstance(log, str):
488488
self.log_file = io.open(log, mode='w')
489489
self.needs_closing = True
490-
else:
491-
if not hasattr(log, 'write'):
492-
raise TypeError('log must be a callable function, file path or '
493-
'file-like object, found %r' % log)
490+
elif hasattr(log, 'write'):
494491
self.log_file = log
495-
self.needs_closing = False
492+
else:
493+
raise TypeError('log must be a callable function, file path or '
494+
'file-like object, found %r' % log)
496495

497496
def __enter__(self):
498497
return self

zarr/creation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
from warnings import warn
23

34
import numpy as np
@@ -17,7 +18,7 @@
1718

1819

1920
def create(shape, chunks=True, dtype=None, compressor='default',
20-
fill_value=0, order='C', store=None, synchronizer=None,
21+
fill_value: Optional[int] = 0, order='C', store=None, synchronizer=None,
2122
overwrite=False, path=None, chunk_store=None, filters=None,
2223
cache_metadata=True, cache_attrs=True, read_only=False,
2324
object_codec=None, dimension_separator=None, write_empty_chunks=True,

zarr/errors.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
class MetadataError(Exception):
42
pass
53

zarr/hierarchy.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
157157
raise ContainsArrayError(path)
158158

159159
# initialize metadata
160+
mkey = None
160161
try:
161162
mkey = _prefix_to_group_key(self._store, self._key_prefix)
162163
assert not mkey.endswith("root/.group")
@@ -633,26 +634,26 @@ def _array_iter(self, keys_only, method, recurse):
633634
yield _key if keys_only else (_key, self[key])
634635
elif recurse and contains_group(self._store, path):
635636
group = self[key]
636-
for i in getattr(group, method)(recurse=recurse):
637-
yield i
637+
yield from getattr(group, method)(recurse=recurse)
638638
else:
639639
dir_name = meta_root + self._path
640640
array_sfx = '.array' + self._metadata_key_suffix
641+
group_sfx = '.group' + self._metadata_key_suffix
642+
641643
for key in sorted(listdir(self._store, dir_name)):
642644
if key.endswith(array_sfx):
643645
key = key[:-len(array_sfx)]
646+
_key = key.rstrip("/")
647+
yield _key if keys_only else (_key, self[key])
648+
644649
path = self._key_prefix + key
645650
assert not path.startswith("meta/")
646-
if key.endswith('.group' + self._metadata_key_suffix):
651+
if key.endswith(group_sfx):
647652
# skip group metadata keys
648653
continue
649-
if contains_array(self._store, path):
650-
_key = key.rstrip("/")
651-
yield _key if keys_only else (_key, self[key])
652654
elif recurse and contains_group(self._store, path):
653655
group = self[key]
654-
for i in getattr(group, method)(recurse=recurse):
655-
yield i
656+
yield from getattr(group, method)(recurse=recurse)
656657

657658
def visitvalues(self, func):
658659
"""Run ``func`` on each object.
@@ -686,8 +687,7 @@ def _visit(obj):
686687
yield obj
687688
keys = sorted(getattr(obj, "keys", lambda: [])())
688689
for k in keys:
689-
for v in _visit(obj[k]):
690-
yield v
690+
yield from _visit(obj[k])
691691

692692
for each_obj in islice(_visit(self), 1, None):
693693
value = func(each_obj)
@@ -1277,6 +1277,7 @@ def group(store=None, overwrite=False, chunk_store=None,
12771277

12781278
path = normalize_storage_path(path)
12791279

1280+
requires_init = None
12801281
if zarr_version == 2:
12811282
requires_init = overwrite or not contains_group(store)
12821283
elif zarr_version == 3:

zarr/storage.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ def normalize_store_arg(store: Any, storage_options=None, mode="r", *,
161161
if zarr_version is None:
162162
# default to v2 store for backward compatibility
163163
zarr_version = getattr(store, "_store_version", DEFAULT_ZARR_VERSION)
164-
elif zarr_version not in [2, 3]:
165-
raise ValueError("zarr_version must be either 2 or 3")
166164
if zarr_version == 2:
167165
normalize_store = _normalize_store_arg_v2
168166
elif zarr_version == 3:
169167
from zarr._storage.v3 import _normalize_store_arg_v3
170168
normalize_store = _normalize_store_arg_v3
169+
else:
170+
raise ValueError("zarr_version must be either 2 or 3")
171171
return normalize_store(store, storage_options, mode)
172172

173173

@@ -597,7 +597,7 @@ def init_group(
597597
store: StoreLike,
598598
overwrite: bool = False,
599599
path: Path = None,
600-
chunk_store: StoreLike = None,
600+
chunk_store: Optional[StoreLike] = None,
601601
):
602602
"""Initialize a group store. Note that this is a low-level function and there should be no
603603
need to call this directly from user code.
@@ -644,7 +644,7 @@ def _init_group_metadata(
644644
store: StoreLike,
645645
overwrite: Optional[bool] = False,
646646
path: Optional[str] = None,
647-
chunk_store: StoreLike = None,
647+
chunk_store: Optional[StoreLike] = None,
648648
):
649649

650650
store_version = getattr(store, '_store_version', 2)
@@ -702,8 +702,7 @@ def _dict_store_keys(d: Dict, prefix="", cls=dict):
702702
for k in d.keys():
703703
v = d[k]
704704
if isinstance(v, cls):
705-
for sk in _dict_store_keys(v, prefix + k + '/', cls):
706-
yield sk
705+
yield from _dict_store_keys(v, prefix + k + '/', cls)
707706
else:
708707
yield prefix + k
709708

@@ -863,8 +862,7 @@ def __eq__(self, other):
863862
)
864863

865864
def keys(self):
866-
for k in _dict_store_keys(self.root, cls=self.cls):
867-
yield k
865+
yield from _dict_store_keys(self.root, cls=self.cls)
868866

869867
def __iter__(self):
870868
return self.keys()
@@ -1462,7 +1460,7 @@ def listdir(self, path=None):
14621460
return sorted(new_children)
14631461
else:
14641462
return children
1465-
except IOError:
1463+
except OSError:
14661464
return []
14671465

14681466
def rmdir(self, path=None):
@@ -1794,8 +1792,7 @@ def keylist(self):
17941792
return sorted(self.zf.namelist())
17951793

17961794
def keys(self):
1797-
for key in self.keylist():
1798-
yield key
1795+
yield from self.keylist()
17991796

18001797
def __iter__(self):
18011798
return self.keys()
@@ -2270,8 +2267,7 @@ def keys(self):
22702267
def values(self):
22712268
with self.db.begin(buffers=self.buffers) as txn:
22722269
with txn.cursor() as cursor:
2273-
for v in cursor.iternext(keys=False, values=True):
2274-
yield v
2270+
yield from cursor.iternext(keys=False, values=True)
22752271

22762272
def __iter__(self):
22772273
return self.keys()
@@ -2581,8 +2577,7 @@ def __contains__(self, key):
25812577

25822578
def items(self):
25832579
kvs = self.cursor.execute('SELECT k, v FROM zarr')
2584-
for k, v in kvs:
2585-
yield k, v
2580+
yield from kvs
25862581

25872582
def keys(self):
25882583
ks = self.cursor.execute('SELECT k FROM zarr')
@@ -2796,12 +2791,10 @@ def keylist(self):
27962791
for key in self.client.keys(self._key('*'))]
27972792

27982793
def keys(self):
2799-
for key in self.keylist():
2800-
yield key
2794+
yield from self.keylist()
28012795

28022796
def __iter__(self):
2803-
for key in self.keys():
2804-
yield key
2797+
yield from self.keys()
28052798

28062799
def __len__(self):
28072800
return len(self.keylist())

0 commit comments

Comments
 (0)