Check and convert the data type of a NumPy array based on a predefined set of data types.
pip install numpytypechecker
Tested against Windows / Python 3.11 / Anaconda
dtypecheck(array, filterna=True, float2int=True, dtypes=(np.uint8,
np.int8,
np.uint16,
np.int16,
np.uint32,
np.int32,
np.uint64,
np.int64,
np.uintp,
np.intp,
np.float16,
np.float32,
np.float64,
'M',
'm',
'O',
'P',
'S',
'U',
'V',
'p',
's',
np.complex64,
np.complex128,
np.datetime64,
np.timedelta64,
np.void, bool, np.bool_,
object
)):
r"""
Check and convert the data type of a NumPy array based on a predefined set of data types.
Parameters:
- array (numpy.ndarray): Input NumPy array.
- filterna (bool, optional): If True, remove NaN values from the array before type checking.
Default is True.
- float2int (bool, optional): If True, convert float arrays to integer if they contain only integers.
Default is True.
- dtypes (tuple, optional): Tuple of NumPy data types to check against. Default includes various numeric,
datetime, timedelta, complex, boolean, and object types.
Returns:
- numpy.ndarray: NumPy array with the converted data type.
Examples:
from numpytypechecker import dtypecheck
import numpy as np
# Example
a1D = np.array([1, 2, 3, 4])
a2D = np.array([[1, 2], [3, 4]])
a3D = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
b1 = np.array([2., 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9])
b2 = np.array([[1., 1., 1., 0.],
[1., 1., 0., 1.],
[0., 0., -3., 0.],
[0., 0., np.nan, -4.]])
print(dtypecheck(a1D, filterna=True, float2int=True, ).dtype)
print(dtypecheck(a2D, filterna=True, float2int=True, ).dtype)
print(dtypecheck(a3D, filterna=True, float2int=True, ).dtype)
print(dtypecheck(b1, filterna=True, float2int=True, ).dtype)
print(dtypecheck(b2, filterna=False, float2int=True, ).dtype)
# uint8
# uint8
# uint8
# float64
# float64
Metadata
Release files for numpytypechecker 0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| numpytypechecker-0.11.tar.gz | 20.9 kB | Without provenance | Details for numpytypechecker-0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| numpytypechecker-0.11-py3-none-any.whl | Python 3 | none | any | Details for numpytypechecker-0.11-py3-none-any.whl |
Total release size: 42.3 kB
Release files / numpytypechecker-0.11.tar.gz
| Download URL | numpytypechecker-0.11.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
721a6feb6cfa6885e669bb314d35bac4ae179edc299cd7e901ffb2579f05cfec
|
|
BLAKE2b-256 checksum How to use checksums |
821d80be8aa50a17743c3b399f0bb3974056bca863712d1ac4bb95911ad201a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / numpytypechecker-0.11-py3-none-any.whl
| Download URL | numpytypechecker-0.11-py3-none-any.whl |
|---|---|
| Size | 21.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17be6850188885670278e2630d10d7957bfe9133b035504d319786602a472cd6
|
|
BLAKE2b-256 checksum How to use checksums |
80f3b5fd595b04243ae3829c3ee58132242eb84bd3bdad88e29f9fa9c0ea6d02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for numpytypechecker 0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.