semvec/pypi-packages huggingface dataset:
ndarraybuffer 0.2.1
NDArray with both-side insertion/deletion and size limit
License: MIT
Requires Python: <4.0,>=3.10

[![Coverage badge](https://raw.githubusercontent.com/lizeyan/ndarraybuffer/python-coverage-comment-action-data/badge.svg)](https://htmlpreview.github.io/?https://github.com/lizeyan/ndarraybuffer/blob/python-coverage-comment-action-data/htmlcov/index.html)

## Introduction
Wrap `numpy.ndarray` to support fast both-side insertion/deletion and size limit.

- Fully typed.
- Directly perform arithmetic operations with NDArray
- pickleable
- JSON serializable

```bash
pip install ndarraybuffer
```

### Both-side insertion/deletion
```python
arr = ArrayBuffer()
arr.extend(np.arange(100))
arr.append(100)
arr.appendleft(0)
arr.pop(1)
arr.popleft(1)
```

### Size limit
```python
arr = ArrayBuffer(max_len=10)
arr.extend(np.arange(10))
assert len(arr) == 10
assert np.array_equal(arr, np.arange(10))
arr.append(10)
assert len(arr) == 10
assert np.array_equal(arr, np.arange(1, 11))
```


### JSON Serialization and Deserialization
```python
arr = ArrayBuffer(max_len=10, dtype=np.float64)
arr.extend(np.arange(10))
state_dict = arr.state_dict()
rec = ArrayBuffer.load(json.loads(json.dumps(state_dict)))
```
ccpf 1.0.0
CPF validation, generation and masking
License: MIT
Requires Python: >=3.10
Keywords: cpf, validation, generation, mask

## ccpf

A CPF (brazilian register numbers for persons) library that can:
* Validate CPFs
* Generate random CPFs
* Apply and remove masks from CPFs
* Check if CPFs are masked

### Install

Just do `pip3 install ccpf` and you are good to go.

### How to use

After `import`ing `ccpf` you can:

* `generate()` - Generate a random valid unmasked CPF.

```
import ccpf
cpf = ccpf.generate()
assert ccpf.validate(cpf)
```

* `validate(cpf)` - Validate if a string is a valid CPF. Works for masked and unmasked CPFs.

```
import ccpf
cpf = ccpf.generate()
assert ccpf.validate(cpf)
```

* `has_mask(cpf)` - Return wheter or not the given CPF is masked. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.

```
import ccpf
cpf = ccpf.generate()
assert not ccpf.has_mask(cpf)
```

* `mask(cpf)` - Return the masked version of the given CPF. If the CPF is already masked, just return it. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.

```
import ccpf
cpf = ccpf.generate()
assert not ccpf.has_mask(cpf)
masked = ccpf.mask(cpf)
assert ccpf.has_mask(masked)
masked2 = ccpf.mask(masked)
assert ccpf.has_mask(masked2)
```

* `unmask(cpf)` - Return unmasked version of the given CPF. If the CPF is already unmasked, just return it. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.

```
import ccpf
cpf = ccpf.generate()
assert not ccpf.has_mask(cpf)
unmasked = ccpf.unmask(cpf)
assert not ccpf.has_mask(unmasked)
masked = ccpf.mask(unmasked)
assert ccpf.has_mask(masked)
unmasked2 = ccpf.unmask(masked)
assert not ccpf.has_mask(unmasked2)
```

#### `CPFInvalidFormat`

A CPF may have a valid _format_, but be invalid:

* without mask but invalid: 
```
invalid_cpf_with_right_format = '12345678901'
assert not ccpf.validate(invalid_cpf_with_right_format)
error = False
try:
    ccpf.unmask(invalid_cpf_with_right_format)
except ccpf.CPFInvalidFormat:
    error = True
finally:
    assert not error
```
* with mask but invalid.
```
invalid_cpf_with_right_format = '123.456.789-01'
assert not ccpf.validate(invalid_cpf_with_right_format)
error = False
try:
    ccpf.unmask(invalid_cpf_with_right_format)
except ccpf.CPFInvalidFormat:
    error = True
finally:
    assert not error
```

* `CPFInvalidFormat` will be raised when the format is invalid. It does not say whether the CPF itself is invalid or not.

```
cpf_with_wrong_format = 'thisisclearlynotinthecpfformat'
assert not ccpf.validate(cpf_with_wrong_format)
error = False
try:
    ccpf.unmask(cpf_with_wrong_format)
except ccpf.CPFInvalidFormat:
    error = True
finally:
    assert error
```

### Run tests

Just execute `tox` by calling it: 

```
tox
```