Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Aug 8, 2023
1 parent f018e17 commit dcada57
Show file tree
Hide file tree
Showing 28 changed files with 10 additions and 310 deletions.
1 change: 0 additions & 1 deletion bench/compress_normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from zarr import blosc

if __name__ == "__main__":

sys.path.insert(0, "..")

# setup
Expand Down
3 changes: 1 addition & 2 deletions zarr/_storage/absstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(
"https://{}.blob.core.windows.net/".format(account_name),
container,
credential=account_key,
**blob_service_kwargs
**blob_service_kwargs,
)

self.client = client
Expand Down Expand Up @@ -240,7 +240,6 @@ def __setitem__(self, key, value):
super().__setitem__(key, value)

def rmdir(self, path=None):

if not path:
# Currently allowing clear to delete everything as in v2

Expand Down
1 change: 0 additions & 1 deletion zarr/_storage/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ def _rmdir_from_keys(store: StoreLike, path: Optional[str] = None) -> None:


def _rmdir_from_keys_v3(store: StoreV3, path: str = "") -> None:

meta_dir = meta_root + path
meta_dir = meta_dir.rstrip("/")
_rmdir_from_keys(store, meta_dir)
Expand Down
1 change: 0 additions & 1 deletion zarr/_storage/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def _get_files_and_dirs_from_path(store, path):


class FSStoreV3(FSStore, StoreV3):

# FSStoreV3 doesn't use this (FSStore uses it within _normalize_key)
_META_KEYS = ()

Expand Down
6 changes: 0 additions & 6 deletions zarr/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Attributes(MutableMapping):
"""

def __init__(self, store, key=".zattrs", read_only=False, cache=True, synchronizer=None):

self._version = getattr(store, "_store_version", 2)
_Store = Store if self._version == 2 else StoreV3
self.store = _Store._ensure_store(store)
Expand Down Expand Up @@ -73,7 +72,6 @@ def __getitem__(self, item):
return self.asdict()[item]

def _write_op(self, f, *args, **kwargs):

# guard condition
if self.read_only:
raise PermissionError("attributes are read-only")
Expand All @@ -89,7 +87,6 @@ def __setitem__(self, item, value):
self._write_op(self._setitem_nosync, item, value)

def _setitem_nosync(self, item, value):

# load existing data
d = self._get_nosync()

Expand All @@ -106,7 +103,6 @@ def __delitem__(self, item):
self._write_op(self._delitem_nosync, item)

def _delitem_nosync(self, key):

# load existing data
d = self._get_nosync()

Expand All @@ -128,7 +124,6 @@ def put(self, d):
self._write_op(self._put_nosync, dict(attributes=d))

def _put_nosync(self, d):

d_to_check = d if self._version == 2 else d["attributes"]
if not all(isinstance(item, str) for item in d_to_check):
# TODO: Raise an error for non-string keys
Expand Down Expand Up @@ -178,7 +173,6 @@ def update(self, *args, **kwargs):
self._write_op(self._update_nosync, *args, **kwargs)

def _update_nosync(self, *args, **kwargs):

# load existing data
d = self._get_nosync()

Expand Down
20 changes: 5 additions & 15 deletions zarr/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,8 @@ def copy_store(

# setup logging
with _LogWriter(log) as log:

# iterate over source keys
for source_key in sorted(source.keys()):

# filter to keys under source path
if source_store_version == 2:
if not source_key.startswith(source_path):
Expand Down Expand Up @@ -756,7 +754,7 @@ def copy(
log=None,
if_exists="raise",
dry_run=False,
**create_kws
**create_kws,
):
"""Copy the `source` array or group into the `dest` group.
Expand Down Expand Up @@ -877,7 +875,6 @@ def copy(

# setup logging
with _LogWriter(log) as log:

# do the copying
n_copied, n_skipped, n_bytes_copied = _copy(
log,
Expand All @@ -889,7 +886,7 @@ def copy(
without_attrs=without_attrs,
if_exists=if_exists,
dry_run=dry_run,
**create_kws
**create_kws,
)

# log a final message with a summary of what happened
Expand Down Expand Up @@ -947,12 +944,10 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_

# take action
if do_copy:

# log a message about what we're going to do
log("copy {} {} {}".format(source.name, source.shape, source.dtype))

if not dry_run:

# clear the way
if exists:
del dest[name]
Expand Down Expand Up @@ -1037,12 +1032,10 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_

# take action
if do_copy:

# log action
log("copy {}".format(source.name))

if not dry_run:

# clear the way
if exists_array:
del dest[name]
Expand All @@ -1055,7 +1048,6 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
grp.attrs.update(source.attrs)

else:

# setup for dry run without creating any groups in the
# destination
if dest is not None:
Expand All @@ -1075,7 +1067,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
without_attrs=without_attrs,
if_exists=if_exists,
dry_run=dry_run,
**create_kws
**create_kws,
)
n_copied += c
n_skipped += s
Expand All @@ -1098,7 +1090,7 @@ def copy_all(
log=None,
if_exists="raise",
dry_run=False,
**create_kws
**create_kws,
):
"""Copy all children of the `source` group into the `dest` group.
Expand Down Expand Up @@ -1188,7 +1180,6 @@ def copy_all(

# setup logging
with _LogWriter(log) as log:

for k in source.keys():
c, s, b = _copy(
log,
Expand All @@ -1200,7 +1191,7 @@ def copy_all(
without_attrs=without_attrs,
if_exists=if_exists,
dry_run=dry_run,
**create_kws
**create_kws,
)
n_copied += c
n_skipped += s
Expand Down Expand Up @@ -1261,7 +1252,6 @@ def is_zarr_key(key):
return key.endswith(".zarray") or key.endswith(".zgroup") or key.endswith(".zattrs")

else:

assert_zarr_v3_api_available()

sfx = _get_metadata_suffix(store) # type: ignore
Expand Down
16 changes: 0 additions & 16 deletions zarr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def _load_metadata_nosync(self):
except KeyError:
raise ArrayNotFoundError(self._path)
else:

# decode and store metadata as instance members
meta = self._store._metadata_class.decode_array_metadata(meta_bytes)
self._meta = meta
Expand Down Expand Up @@ -1358,7 +1357,6 @@ def get_mask_selection(self, selection, out=None, fields=None):
return self._get_selection(indexer=indexer, out=out, fields=fields)

def _get_selection(self, indexer, out=None, fields=None):

# We iterate over all chunks which overlap the selection and thus contain data
# that needs to be extracted. Each chunk is processed in turn, extracting the
# necessary data and storing into the correct location in the output array.
Expand Down Expand Up @@ -1983,7 +1981,6 @@ def _set_basic_selection_nd(self, selection, value, fields=None):
self._set_selection(indexer, value, fields=fields)

def _set_selection(self, indexer, value, fields=None):

# We iterate over all chunks which overlap the selection and thus contain data
# that needs to be replaced. Each chunk is processed in turn, extracting the
# necessary data from the value array and storing into the chunk array.
Expand Down Expand Up @@ -2018,7 +2015,6 @@ def _set_selection(self, indexer, value, fields=None):
):
# iterative approach
for chunk_coords, chunk_selection, out_selection in indexer:

# extract data to store
if sel_shape == ():
chunk_value = value
Expand Down Expand Up @@ -2077,7 +2073,6 @@ def _process_chunk(
and not self._filters
and self._dtype != object
):

dest = out[out_selection]
# Assume that array-like objects that doesn't have a
# `writeable` flag is writable.
Expand All @@ -2088,7 +2083,6 @@ def _process_chunk(
)

if write_direct:

# optimization: we want the whole chunk, and the destination is
# contiguous, so we can decompress directly from the chunk
# into the destination array
Expand Down Expand Up @@ -2321,28 +2315,24 @@ def _process_for_setitem(self, ckey, chunk_selection, value, fields=None):
# to access the existing chunk data

if is_scalar(value, self._dtype):

# setup array filled with value
chunk = np.empty_like(
self._meta_array, shape=self._chunks, dtype=self._dtype, order=self._order
)
chunk.fill(value)

else:

# ensure array is contiguous
chunk = value.astype(self._dtype, order=self._order, copy=False)

else:
# partially replace the contents of this chunk

try:

# obtain compressed data for chunk
cdata = self.chunk_store[ckey]

except KeyError:

# chunk not initialized
if self._fill_value is not None:
chunk = np.empty_like(
Expand All @@ -2359,7 +2349,6 @@ def _process_for_setitem(self, ckey, chunk_selection, value, fields=None):
)

else:

# decode chunk
chunk = self._decode_chunk(cdata)
if not chunk.flags.writeable:
Expand Down Expand Up @@ -2429,7 +2418,6 @@ def _decode_chunk(self, cdata, start=None, nitems=None, expected_shape=None):
return chunk

def _encode_chunk(self, chunk):

# apply filters
if self._filters:
for f in self._filters:
Expand Down Expand Up @@ -2619,7 +2607,6 @@ def __setstate__(self, state):
self.__init__(**state)

def _synchronized_op(self, f, *args, **kwargs):

if self._synchronizer is None:
# no synchronization
lock = nolock
Expand All @@ -2636,7 +2623,6 @@ def _synchronized_op(self, f, *args, **kwargs):
return result

def _write_op(self, f, *args, **kwargs):

# guard condition
if self._read_only:
raise ReadOnlyError()
Expand Down Expand Up @@ -2676,7 +2662,6 @@ def resize(self, *args):
return self._write_op(self._resize_nosync, *args)

def _resize_nosync(self, *args):

# normalize new shape argument
old_shape = self._shape
new_shape = normalize_resize_args(old_shape, *args)
Expand Down Expand Up @@ -2755,7 +2740,6 @@ def append(self, data, axis=0):
return self._write_op(self._append_nosync, data, axis=axis)

def _append_nosync(self, data, axis=0):

# ensure data is array-like
if not hasattr(data, "shape"):
data = np.asanyarray(data, like=self._meta_array)
Expand Down
2 changes: 0 additions & 2 deletions zarr/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def create(


def _kwargs_compat(compressor, fill_value, kwargs):

# to be compatible with h5py, as well as backwards-compatible with Zarr
# 1.x, accept 'compression' and 'compression_opts' keyword arguments

Expand Down Expand Up @@ -697,7 +696,6 @@ def open_array(


def _like_args(a, kwargs):

shape, chunks = _get_shape_chunks(a)
if shape is not None:
kwargs.setdefault("shape", shape)
Expand Down
Loading

0 comments on commit dcada57

Please sign in to comment.