# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_errs.ipynb.

# %% auto 0
__all__ = ['AxisError', 'DimsError']

# %% ../nbs/04_errs.ipynb 4
from typing import Optional

from ispec.dun import getname
from ispec.types import iscls

from .atyp import AxisKey
# from narr.axis import naxis
# from narr.axes import naxes

# %% ../nbs/04_errs.ipynb 6
class AxisError(KeyError):
     def __init__(self, key: AxisKey = None, cls: type = 'naxes'):
          nym = getname(cls) if iscls(cls) else str(cls)
          msg = f'Axis {key} not found in {nym}'
          self.key, self.cls, self.msg = (key, cls, msg)
          super().__init__(msg)

# %% ../nbs/04_errs.ipynb 7
class DimsError(ValueError):
     def __init__(self, dims: Optional[list] = None, ndim: Optional[int] = None, cls: type = 'naxes'):
          nym = getname(cls) if iscls(cls) else str(cls)
          msg = f'{nym} must have {len(dims)} dimensions, but got {ndim}.'
          if dims is None or ndim is None:
               msg = f'{nym} dims do not match shape of underlying numpy ndarray.'
               
          self.dims, self.ndim, self.msg, self.cls = (dims, ndim, msg, cls)
          super().__init__(msg)
