Arraykit
Arraykit provides low-level array utilities, often used by StaticFrame, for efficient data manipulation, type checking, and array transformations. It is currently at version 1.2.1 and follows an infrequent release cadence, often aligning with StaticFrame updates.
Common errors
-
ModuleNotFoundError: No module named 'arraykit'
cause The 'arraykit' package has not been installed in the current Python environment.fixRun `pip install arraykit` to install the package. -
AttributeError: module 'arraykit' has no attribute 'astype_array'
cause The specific function `astype_array` was added in version 1.1.0. This error occurs if you are using an older version of arraykit or have a typo in the function name.fixUpgrade your arraykit installation to the latest version (`pip install --upgrade arraykit`) or verify the function name against the documentation for your installed version. -
ValueError: invalid literal for int() with base 10: 'a'
cause This error typically occurs when using `astype_array` (or similar functions) to convert a sequence containing non-numeric strings to a numeric NumPy dtype (e.g., `np.int64`, `np.float64`).fixEnsure that all elements in the input sequence are compatible with the target `dtype`. If the sequence contains mixed types (e.g., strings and numbers), consider using `dtype=object` or pre-process the data to handle non-numeric values.
Warnings
- breaking NumPy `datetime64` scalar lookups in `AutoMap` and `FrozenAutoMap` (internal `arraykit` classes) explicitly require matching units for comparisons and indexing.
- gotcha Arraykit relies heavily on NumPy. Users unfamiliar with NumPy dtypes and array-like structures may encounter unexpected behavior or errors when passing incompatible data types to arraykit functions.
- gotcha As a utility library, arraykit functions are typically imported directly from the top-level package (e.g., `from arraykit import some_function`). Attempting to access functions via nested modules might fail or be incorrect.
Install
-
pip install arraykit
Imports
- astype_array
from arraykit import astype_array
- is_objectable
from arraykit import is_objectable
- delimited_to_arrays
from arraykit import delimited_to_arrays
Quickstart
import numpy as np
from arraykit import astype_array
# Convert a list to a NumPy array with a specified dtype
data_int = [1, 2, 3, 4]
array_float = astype_array(data_int, dtype=np.float64)
print(f"Original list: {data_int}")
print(f"Converted array (float64): {array_float}, dtype: {array_float.dtype}\n")
# Convert mixed data; typically results in an object dtype if types are incompatible
mixed_data = [10, 'hello', 20.5, True]
array_object = astype_array(mixed_data)
print(f"Original mixed data: {mixed_data}")
print(f"Converted array (object): {array_object}, dtype: {array_object.dtype}\n")
# Using is_objectable
from arraykit import is_objectable
print(f"Is 'hello' objectable? {is_objectable('hello')}")
print(f"Is np.datetime64('2023-01-01') objectable? {is_objectable(np.datetime64('2023-01-01'))}")