Skip to main content

Cages in Pandas

Project description

Getting started with Captivity

The only purpose of captivity is to support you in writing better pandas code by caging in some of its worst excentricities. pandas is great, but import captivity; import pandas as pd is better.

The philosophy behind captivity is that there's nothing worse than silent failure. If you didn't ask pandas to automagically correct your arguments, it shouldn't.

Example

To find a comprehensive set of examples, check out the captivity/tests/ directory. To pique your interest, consider the following:

import pandas as pd

a = pd.DataFrame({
    "x": [1, 2], 
    "y": [3, 4]}
)

b = pd.DataFrame({
    "z": [5, 6],
    "x": [9, 0]
})

a_b = pd.concat([a, b], axis=1)

print(a_b)
>>    x  y  z  x
>> 0  1  3  5  9
>> 1  2  4  6  0 

Woa! That should definitely not be allowed by default. With captivity, it's not.

import captivity
a_b = pd.concat([a, b], axis=1)

>> Traceback (most recent call last):
>> ...
>> captivity.CaptivityException: Column-wise concatenation would result in duplicate column labels for column: {'x'}

In addition, captivity currently supports:

  • sensible checks on vertical concatenation (column sets must match)
  • sensible checks on merges (no more _x and _y columns - except when suffixes=("_x", "_y") is passed explicitly)
  • turning CaptivityExceptions into CaptivityWarnings - useful when first using captivity in an existing codebase

Does it also catch <Issue X> ?

captivity is a labor not of love, but of annoying bugs I find in my own code that are caused by careless default arguments in pandas. If you find one in yours that you'd like captivity to patch, please raise an issue on GitHub or contact me directly (or better yet, implement it and put out a PR!)

Running the tests

To test captivity, run pytest --cov in the root directory of this project.

Installation

To install captivity, simply run pip install git+https://github.com/maxsnijders/captivity.git.

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

captivity-0.1.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

captivity-0.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: captivity-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.7

File hashes

Hashes for captivity-0.1.2.tar.gz
Algorithm Hash digest
SHA256 39b10b97f430e0a021955d2a53ff9123f9770002b838dea04a1da273ce38d2d0
MD5 2952e364ee065da6d9d8676cbd04f27e
BLAKE2b-256 c63635f0093382535afbb10ec75ac4064bbad87f614a08077ddd79eff73c018f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: captivity-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.7

File hashes

Hashes for captivity-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 39c453b9ba40319a7decb085cf4b56a8282fbb7956a6d6111c0b8508eca4c2c8
MD5 e21b4d0fc106f7073ea0bdc30847e941
BLAKE2b-256 31fddb153fb97326fb65d9623626e5bfe7a97efed237eb7caef57dac6bef1b6d

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