Skip to content

Remove error utils function (not used anymore) #614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Next release
By :user:`Elliott Sales de Andrade <QuLogic>`; :issue:`442`

* Many of the convenience functions to emit errors (``err_*`` from
``zarr.errors`` have been replaced by ``ValueError`` subclasses. The
functions are deprecated and will be removed in the future. :issue:`590` )
``zarr.errors`` have been replaced by ``ValueError`` subclasses. The corresponding
``err_*`` function have been removed. :issue:`590`, :issue:`614`)

* Improve consistency of terminology regarding arrays and datasets in the
documentation.
Expand Down
56 changes: 20 additions & 36 deletions zarr/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,35 @@ def __init__(self, *args):
super().__init__(self._msg.format(*args))


class ContainsGroupError(_BaseZarrError):
_msg = "path {0!r} contains a group"
class _BaseZarrIndexError(IndexError):
_msg = ""

def __init__(self, *args):
super().__init__(self._msg.format(*args))


def err_contains_group(path):
raise ContainsGroupError(path) # pragma: no cover
class ContainsGroupError(_BaseZarrError):
_msg = "path {0!r} contains a group"


class ContainsArrayError(_BaseZarrError):
_msg = "path {0!r} contains an array"


def err_contains_array(path):
raise ContainsArrayError(path) # pragma: no cover


class ArrayNotFoundError(_BaseZarrError):
_msg = "array not found at path %r' {0!r}"


def err_array_not_found(path):
raise ArrayNotFoundError(path) # pragma: no cover


class GroupNotFoundError(_BaseZarrError):
_msg = "group not found at path {0!r}"


def err_group_not_found(path):
raise GroupNotFoundError(path) # pragma: no cover


class PathNotFoundError(_BaseZarrError):
_msg = "nothing found at path {0!r}"


def err_path_not_found(path):
raise PathNotFoundError(path) # pragma: no cover


def err_bad_compressor(compressor):
raise ValueError('bad compressor; expected Codec object, found %r' %
compressor)
class BadCompressorError(_BaseZarrError):
_msg = "bad compressor; expected Codec object, found {0!r}"


class FSPathExistNotDir(GroupNotFoundError):
Expand All @@ -70,25 +56,23 @@ def __init__(self):
super().__init__("object is read-only")


def err_read_only():
raise ReadOnlyError() # pragma: no cover

class BoundsCheckError(_BaseZarrIndexError):
_msg = "index out of bounds for dimension with length {0}"

def err_boundscheck(dim_len):
raise IndexError('index out of bounds for dimension with length {}'
.format(dim_len))


def err_negative_step():
raise IndexError('only slices with step >= 1 are supported')
class NegativeStepError(IndexError):
def __init__(self):
super().__init__("only slices with step >= 1 are supported")


def err_too_many_indices(selection, shape):
raise IndexError('too many indices for array; expected {}, got {}'
.format(len(shape), len(selection)))


def err_vindex_invalid_selection(selection):
raise IndexError('unsupported selection type for vectorized indexing; only '
'coordinate selection (tuple of integer arrays) and mask selection '
'(single Boolean array) are supported; got {!r}'.format(selection))
class VindexInvalidSelectionError(_BaseZarrIndexError):
_msg = (
"unsupported selection type for vectorized indexing; only "
"coordinate selection (tuple of integer arrays) and mask selection "
"(single Boolean array) are supported; got {0!r}"
)
18 changes: 11 additions & 7 deletions zarr/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import numpy as np

from zarr.errors import (err_boundscheck, err_negative_step,
err_too_many_indices, err_vindex_invalid_selection)
from zarr.errors import (
NegativeStepError,
err_too_many_indices,
VindexInvalidSelectionError,
BoundsCheckError,
)


def is_integer(x):
Expand Down Expand Up @@ -47,7 +51,7 @@ def normalize_integer_selection(dim_sel, dim_len):

# handle out of bounds
if dim_sel >= dim_len or dim_sel < 0:
err_boundscheck(dim_len)
raise BoundsCheckError(dim_len)

return dim_sel

Expand Down Expand Up @@ -102,7 +106,7 @@ def __init__(self, dim_sel, dim_len, dim_chunk_len):
# normalize
self.start, self.stop, self.step = dim_sel.indices(dim_len)
if self.step < 1:
err_negative_step()
raise NegativeStepError()

# store attributes
self.dim_len = dim_len
Expand Down Expand Up @@ -386,7 +390,7 @@ def wraparound_indices(x, dim_len):

def boundscheck_indices(x, dim_len):
if np.any(x < 0) or np.any(x >= dim_len):
err_boundscheck(dim_len)
raise BoundsCheckError(dim_len)


class IntArrayDimIndexer(object):
Expand Down Expand Up @@ -757,7 +761,7 @@ def __getitem__(self, selection):
elif is_mask_selection(selection, self.array):
return self.array.get_mask_selection(selection, fields=fields)
else:
err_vindex_invalid_selection(selection)
raise VindexInvalidSelectionError(selection)

def __setitem__(self, selection, value):
fields, selection = pop_fields(selection)
Expand All @@ -768,7 +772,7 @@ def __setitem__(self, selection, value):
elif is_mask_selection(selection, self.array):
self.array.set_mask_selection(selection, value, fields=fields)
else:
err_vindex_invalid_selection(selection)
raise VindexInvalidSelectionError(selection)


def check_fields(fields, dtype):
Expand Down
6 changes: 3 additions & 3 deletions zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from zarr.errors import (
MetadataError,
err_bad_compressor,
BadCompressorError,
ContainsArrayError,
ContainsGroupError,
FSPathExistNotDir,
Expand Down Expand Up @@ -398,8 +398,8 @@ def _init_array_metadata(
if compressor:
try:
compressor_config = compressor.get_config()
except AttributeError:
err_bad_compressor(compressor)
except AttributeError as e:
raise BadCompressorError(compressor) from e

# obtain filters config
if filters:
Expand Down