Skip to main content

A package for applying efficient groupby operations.

Project description

<sjoshistrats>

fastgrouper

Allows for fast groupby-apply operations, in python.

Install

Users can install the package from PyPI via:

python -m pip install fastgrouper

Usage

Use the arr interface, for numpy array focused applications.

import numpy as np
import fastgrouper.arr
  
def baz(x, y):
    return np.mean(x + y) - 3

# Sample arrays, to slice
xvals = np.array([1, 2, 10])
yvals = np.array([4, 5, 6])
  
# Group ids
gids  = np.array([1, -3, 1])

# Perform groupby-apply; note that keyword args are supported as well.
grpd = fastgrouper.arr.Grouped(gids)
result = grpd.apply(baz, xvals, y=yvals) # np.array([7.5, 4])

# The gids correponding to the result above can be found via the `dedup_gids` attribute.
grpd.dedup_gids # np.array([ 1, -3])

# Users can also perform groupby-apply, and then expand results back to align with the original gids.
result = grpd.apply_expand(baz, xvals, yvals) # np.array([7.5, 4, 7.5])

The li interface returns the results over the groups as a list (instead of an array); this may be useful for functions that return different-sized results. Note that in all interfaces (e.g. both arr and li), the order in which the group elements appear is preserved when the group slices are passed to the function being applied.

import numpy as np
import fastgrouper.li
  
def bop(x):
    return list(x)

# Sample arrays, to slice
xvals = np.array([2, 3, 4])
  
# Group ids
gids  = np.array([10, -20, 10])

grpd = fastgrouper.li.Grouped(gids)
grpd.apply(bop, xvals) # [[2, 4], [3]]

For additional examples, checkout the tests.

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

fastgrouper-0.1.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distributions

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

fastgrouper-0.1.2-py3.8.egg (10.3 kB view details)

Uploaded Egg

fastgrouper-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file fastgrouper-0.1.2.tar.gz.

File metadata

  • Download URL: fastgrouper-0.1.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.8

File hashes

Hashes for fastgrouper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d90b2cd98a2f8bd6dc3cddc8aa32fa5f58b68b902a2e20c2f747f353068fcb11
MD5 235c28140a043dbcf47075ae1cdb0e73
BLAKE2b-256 4b3dee75e9c42a6b54c5b28b86503b4cfe912bba3926e3010e105dceb8ce27d0

See more details on using hashes here.

File details

Details for the file fastgrouper-0.1.2-py3.8.egg.

File metadata

  • Download URL: fastgrouper-0.1.2-py3.8.egg
  • Upload date:
  • Size: 10.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.8

File hashes

Hashes for fastgrouper-0.1.2-py3.8.egg
Algorithm Hash digest
SHA256 0fe8e7b3a9544a54fb94c1b5e31a54947a878bcdee0d6adb74701d5a6f8ee43b
MD5 e79498c52e686549fa608b5382f70436
BLAKE2b-256 e73b543b7d5843a7d32e7096474a094a9cd34c2a25dcd32c1c5a23c045600ecc

See more details on using hashes here.

File details

Details for the file fastgrouper-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fastgrouper-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.8

File hashes

Hashes for fastgrouper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 01ec249a2871d8a5b11c76d37dbb2e51c120b627c5e9864452ad9f0a15d3e95f
MD5 ddacaf8ebc225893975589bad4b4a4b4
BLAKE2b-256 480ffd795181bb60d9f58ca58d6115ed7f4f6156320154b2be3330af1e9c758e

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