Skip to main content

Pandas Interval Set Operations: methods for set operations, analytics, lookups and joins on pandas' Interval, IntervalArray and IntervalIndex

Project description

piso logo

piso - pandas interval set operations

piso exists to bring set operations (union, intersection, difference + more), analytical methods, and lookup and join functionality to pandas' interval classes, specifically

- pandas.Interval
- pandas.arrays.IntervalArray
- pandas.IntervalIndex

Currently, there is a lack of such functionality in pandas, although it has been earmarked for development. Until this eventuates, piso aims to fill the void. Many of the methods can be used via accessors, which can be registered to pandas.arrays.IntervalArray and pandas.IntervalIndex classes, for example:

>>> import pandas as pd
>>> import piso
>>> piso.register_accessors()

>>> arr = pd.arrays.IntervalArray.from_tuples(
...        [(1,5), (3,6), (2,4)]
...    )

>>> arr.piso.intersection()
<IntervalArray>
[(3, 4]]
Length: 1, closed: right, dtype: interval[int64]

>>> arr.piso.contains([2, 3, 5])
            2      3      5
(1, 5]   True   True   True
(3, 6]  False  False   True
(2, 4]  False   True  False

>>> df = pd.DataFrame(
...     {"A":[4,3], "B":["x","y"]},
...     index=pd.IntervalIndex.from_tuples([(1,3), (5,7)]),
... )

>>> s = pd.Series(
...     [True, False],
...     index=pd.IntervalIndex.from_tuples([(2,4), (5,6)]),
...     name="C",
... )

>>> piso.join(df, s)
        A  B      C
(1, 2]  4  x    NaN
(2, 3]  4  x   True
(5, 6]  3  y  False
(6, 7]  3  y    NaN

>>> piso.join(df, s, how="inner")
        A  B      C
(2, 3]  4  x   True
(5, 6]  3  y  False

The domain of the intervals can be either numerical, pandas.Timestamp or pandas.Timedelta.

Several case studies using piso can be found in the user guide. Further examples, and a detailed explanation of functionality, are provided in the API reference.

Visit https://piso.readthedocs.io for the documentation.

Installation

piso can be installed from PyPI or Anaconda.

To install the latest version from PyPI::

python -m pip install piso

To install the latest version through conda-forge::

conda install -c conda-forge piso

Versioning

SemVer is used by piso for versioning releases. For versions available, see the tags on this repository.

License

This project is licensed under the MIT License

Acknowledgments

Currently, piso is a pure-python implentation which relies heavily on staircase and pandas. It is designed to operate as part of the pandas ecosystem. The colours for the piso logo have been assimilated from pandas as a homage, and is not to intended to imply and affiliation with, or endorsement by, pandas.

Additionally, two classes have been borrowed, almost verbatim, from the pandas source code:

- `pandas.util._decorators.Appender`
- `pandas.core.accessor.CachedAccessor`

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

piso-1.1.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

piso-1.1.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file piso-1.1.0.tar.gz.

File metadata

  • Download URL: piso-1.1.0.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for piso-1.1.0.tar.gz
Algorithm Hash digest
SHA256 12f31cb2c81a8a1d13ca810281fac1374f037b8e2862fb6b42a0787c8752da88
MD5 d15c53424429772b1a924ebc5d7e242a
BLAKE2b-256 55d0d22eb50109f1a5e624eab3c17b0c377d0f28ed25bda48a426bebc3c09782

See more details on using hashes here.

File details

Details for the file piso-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: piso-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for piso-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 423ee4bae88fe7f2d97a046fde451aa558e8eb89ebb7dfafc57878eb703254d9
MD5 c6b6c327109c600a8c38254bac8a3e69
BLAKE2b-256 f5bf655311351719cd0da6903788f29fa3d95090caf44e388bcbdbeb7f602626

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