Beispiel #1
0
 def __init__(self, max_token_len: int = None, key: str = None):
     typecheck.check_arg(max_token_len, (int, type(None)))
     typecheck.check_arg(key, (str, bytes, type(None)))
     super().__init__(dtype=dtypes.String)
     self._max_token_len = max_token_len
     if isinstance(key, str):
         key = key.encode()
     self._key = key or secrets.token_bytes(8)
Beispiel #2
0
def test_typecheck_more_types_fails():
    args_list, types_list = _make_args_and_types()
    arg = args_list[-1]
    types = types_list[:3]
    try:
        typecheck.check_arg(arg, types)
        raise AssertionError
    except ValueError:
        pass
Beispiel #3
0
 def __init__(self, key, encoding="utf-8"):
     typecheck.check_arg(key, (str, bytes))
     typecheck.check_arg(encoding, str)
     super().__init__(dtype=dtypes.String)
     if isinstance(key, str):
         key = key.encode()
     if len(key) != 32:
         raise ValueError(f"Key must be exactly 32 bytes, got {len(key)}")
     self.key = key
     self.encoding = encoding
Beispiel #4
0
def test_typecheck_args():
    args_list, types_list = _make_args_and_types()
    # check passing
    for a, t in zip(args_list, types_list):
        typecheck.check_arg(a, t)
    # check failure
    for a, t in zip(args_list, types_list[::-1]):
        try:
            typecheck.check_arg(a, t)
            raise AssertionError
        except ValueError:
            pass
 def __init__(
     self,
     dtype: dtypes.Numerics,
     min: Union[int, float],
     max: Union[int, float],
     seed: Optional[int] = None,
 ):
     assert dtype in dtypes.Numerics
     typecheck.check_arg(min, (int, float))
     typecheck.check_arg(max, (int, float))
     typecheck.check_arg(seed, (int, type(None)))
     super().__init__(dtype)
     self._min = min
     self._max = max
     self._rng = np.random.default_rng(seed=seed)
Beispiel #6
0
 def __init__(
     self,
     dtype: dtypes.DType,
     min: (int, float),
     max: (int, float),
     seed: Optional[int] = None,
 ):
     assert dtype in dtypes.Numerics
     typecheck.check_arg(min, (int, float))
     typecheck.check_arg(max, (int, float))
     typecheck.check_arg(seed, (int, type(None)))
     super().__init__(dtype)
     self._min = min
     self._max = max
     self._seed = seed
Beispiel #7
0
 def __init__(self, frequency: str):
     typecheck.check_arg(frequency, str)
     super().__init__(dtypes.Date)
     self._frequency = frequency.lower()
Beispiel #8
0
 def __init__(self, dtype: dtypes.DType, precision: int):
     if dtype not in dtypes.Numerics:
         raise ValueError("NumericRounding requires a Numeric dtype.")
     typecheck.check_arg(precision, int)
     super().__init__(dtype)
     self._precision = precision
Beispiel #9
0
def test_typecheck_more_types_passes():
    args_list, types_list = _make_args_and_types()
    args = args_list[:3]
    types = types_list[:3]
    for arg in args:
        typecheck.check_arg(arg, types)