Skip to main content

pdrepr

pdrepr takes a pandas DataFrame as input, and attempts to output a valid Python expression that will create an identical DataFrame. Supports multiindices for rows and columns, at least for the relatively simple cases I have tested. DataFrames with datatypes other than strings, ints and floats should work if their _repr__() method also returns a string that can be passed to eval(), resulting in a similar object.

Testing and linting codecov GitHub release (latest by date including pre-releases) PyPI

Motivation

I was tired of having to manually construct DataFrames to be used in testing, especially the reference object to be compared with the resulting DF. With this package, such a code snipped can be created from the resulting DF.

Installation

Using poetry:

poetry add pdrepr

Using pipenv:

pipenv install pdrepr

Using pip:

pip install pdrepr

Usage

>>> from pdrepr import pdrepr

>>> pdrepr(df)
pd.DataFrame({'character': ['The Nude Organist', 'BBC continuity announcer', 'The Colonel'], 'played by': ['Terry Jones and Terry Gilliam', 'John Cleese', 'Graham Chapman']}).set_index(['character'])

>>> pd.DataFrame({'character': ['The Nude Organist', 'BBC continuity announcer', 'The Colonel'], 'played by': ['Terry Jones and Terry Gilliam', 'John Cleese', 'Graham Chapman']}).set_index(['character'])
                                              played by
character                                              
The Nude Organist         Terry Jones and Terry Gilliam
BBC continuity announcer                    John Cleese
The Colonel                              Graham Chapman

Metadata

Release files for pdrepr 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdrepr 0.2.1
File Size Uploaded
pdrepr-0.2.1.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdrepr 0.2.1
File Interpreter ABI Platform
pdrepr-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.0 kB

Release files / pdrepr-0.2.1.tar.gz

Download URL pdrepr-0.2.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
104cb246e40faaf4a7c9c5687234f2ab2e82ac47756514d1145184befca272e8
BLAKE2b-256 checksum
How to use checksums
71f3f6754dd020608c15e8bc635dfbb9a3fac519ba9ed3ab61820432b2c5834f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.0 Linux/5.13.0-1029-azure

Release files / pdrepr-0.2.1-py3-none-any.whl

Download URL pdrepr-0.2.1-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47918c503527f75e022b0bf66eba64116bf0d6226d31d86ea3ff215e5bc57094
BLAKE2b-256 checksum
How to use checksums
c37b0a7d411352adbe66c97fb6ddb2b6d9f262e7a0629d5357a3a4f9a2bc2702
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.0 Linux/5.13.0-1029-azure

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page