Skip to main content

Module to implement C extension Bins class for bin-based storage of items

Project description

Description

binstore module with Bins C extension to implement storage of items based on value-based binning where binned value determines ordinal index into array where item is stored. Supports item assignment and slice operations.

Members

  • min - float, minimum value
  • max - float, maximum value
  • width - float, bin width
  • n_bins - int, number of bins = int((max - min) / width) + 1

Methods

  • bin(value) - perform binning operation on value and returns corresponding bin ordinal value 0 <= n <= n_bins - 1
  • put(value, item) - puts item into bin n = bin(value) and returns n
  • get(value) - gets item from bin n = bin(value) and returns as tuple of (item, n)
  • items() - returns items in bins as dict with left bin edge as key, item in bin as value

When performing binning:

  1. if value is <= min, bin(value) = 0
  2. if value is >= max, bin(value) = n_bins - 1
  3. if value is >= half the distance between left edge of bin n and left edge of bin n+1, then corresponding bin(value) = n+1, otherwise bin(value) = n. e.g., for min = 0.0, max = 1.0, width = 0.01, bin(0.106) = 11, bin(0.103) = 10.

Example:

>>>b = Bins(min=0.0, max=1.0, width=0.01) >>>for i in range(50): >>> b.put(i/100, {'i': i}) 0 1 2 . 49 >>>b.get(0.005) ({'i': 1}, 1) >>>b.get(0.000) ({'i': 0}, 0) >>>b.get(0.004) ({'i': 0}, 0) >>>b.get(0.103) ({'i': 10}, 10) >>>b.get(0.106) ({'i': 11}, 11) >>>b.put(0.106, {'foo': 'bar'}) 11 >>>b[11] {'foo': 'bar'} >>>b[11] = {'bar': 'foo'} >>>b[11] {'bar': 'foo'}

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

binstore-1.7.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

binstore-1.7.1-cp38-cp38-win_amd64.whl (12.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

Details for the file binstore-1.7.1.tar.gz.

File metadata

  • Download URL: binstore-1.7.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

File hashes

Hashes for binstore-1.7.1.tar.gz
Algorithm Hash digest
SHA256 2edca2d76084c28349d3bbe0652b8de5159b6ba36a06dc55865c624cbfad3775
MD5 400b5b6eae758317780c4e87c27ac2d9
BLAKE2b-256 af312bf20ad78f05185c5bcdeac592f95cf2794d933103b5f4de2a37ca72cafe

See more details on using hashes here.

File details

Details for the file binstore-1.7.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: binstore-1.7.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

File hashes

Hashes for binstore-1.7.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 74860d820b50c5b10c8b3372a534950c3d8b7fc541b6631ae4877993c4248c5f
MD5 d64c4613cdfd52c1efdca842828bd30b
BLAKE2b-256 50df5483e2efd8f66a441c52aa38175e5b4c61c840b35f949a5d49758ba7362c

See more details on using hashes here.

Supported by

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