Like a numpy-recarray but dynamically appendable.
Project description
A dynamic, appandable version of Numpy’s recarray. The goal is to have a recarray-like-object which can be appended to in a transparent and efficient way.
install
pip install dynamicsizerecarray
basic use
Initialize an empty DynamicSizeRecarray with a dtype.
import dynamicsizerecarray
dra = dynamicsizerecarray.DynamicSizeRecarray(
dtype=[("hour", "u1"), ("minute", "u1"), ("temperature", "f8")]
)
len(dra)
0
Or initialize the DynamicSizeRecarray with an already existing recarray.
import numpy
rec = numpy.core.records.recarray(
shape=1,
dtype=[("hour", "u1"), ("minute", "u1"), ("temperature", "f8")],
)
rec["hour"][0] = 2
rec["minute"][0] = 13
rec"temperature"][0] = 20.123
dra = dynamicsizerecarray.DynamicSizeRecarray(recarray=rec)
len(dra)
1
After initializing, the DynamicSizeRecarray can be appended to dynamically. You can append a record, i.e. a dict.
dra.append_record({"hour": 3, "minute": 53, "temperature": 22.434})
len(dra)
2
Or you can append another recarray.
rec = numpy.core.records.recarray(
shape=1,
dtype=[("hour", "u1"), ("minute", "u1"), ("temperature", "f8")],
)
rec["hour"][0] = 13
rec["minute"][0] = 41
rec"temperature"][0] = 18.623
dra.append_recarray(rec)
len(dra)
3
When the dynamic appending is done, the DynamicSizeRecarray can be exported to a classic, and static recarray.
final = dra.to_recarray()
Further the DynamicSizeRecarray provides the properties shape and dtype, and also implements __gettitem__, __setitem__.
dra.shape # shape
(3, )
dra[0] # __gettitem__
(2, 13, 20.123)
dra[1] = (7, 25, 21.45) # __setitem__
len(dra) # __len__
3
dra.dtype # exposes the internal recarray's dtype
dtype((numpy.record, [('hour', 'u1'), ('minute', 'u1'), ('temperature', '<f8')]))
wording
- record: A dict with keys (and values) matching the dtype of
the DynamicSizeRecarray. (Wording is adopted from pandas).
records is just a list of record``s (Also adopted from ``pandas).
recarray: Is short for np.core.records.recarray.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dynamicsizerecarray-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 443d523fd1525c0963e635e11ca3ac47a8ba408165543fc29f0273f661bf6057 |
|
MD5 | 7708dc41c64de9f7c08923000c148d15 |
|
BLAKE2b-256 | 0b09bfe8882fc66c0e8d7123a0a70dd01f351e91e2e49295e1a5665796a3e2c8 |
Hashes for dynamicsizerecarray-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d2001c15eed28fa44782ef18515fa45ece189c3fd2fba6f1f57a5d84204e4c4 |
|
MD5 | 95e473a7c0e3729fe3024d4a712f79bb |
|
BLAKE2b-256 | bcd8f031c95c1125730de39f797b8d5624dfd8dc22c2ce4c76efa947229a2672 |