Skip to main content

Like a numpy-recarray but dynamically appendable.

Project description

TestStatus PyPiStatus BlackStyle BlackPackStyle MITLicenseBadge

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.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.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 is 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.recarray.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dynamicsizerecarray-0.0.12.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dynamicsizerecarray-0.0.12-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file dynamicsizerecarray-0.0.12.tar.gz.

File metadata

  • Download URL: dynamicsizerecarray-0.0.12.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dynamicsizerecarray-0.0.12.tar.gz
Algorithm Hash digest
SHA256 e397281a65c50f1183a23e74ebadc039a4cab6dfd8efaebb6d8e0b670fa6fa65
MD5 f085f262384442c85f4cd3dead51dc12
BLAKE2b-256 3e105a9960479a835dbd52d77995ac600c40e2a65a15602d886709d5a261b766

See more details on using hashes here.

File details

Details for the file dynamicsizerecarray-0.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamicsizerecarray-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 5dcd7750399b8a222978e18b771d556237fd7d3e5b8ca2e587d572b398ccb673
MD5 ae3142b2924006a2f59b5686f146cc3a
BLAKE2b-256 c37e9a3afdecf24b14daec5165010f75fc866b3ecd33642dd47c0cb3045ea20b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page