Skip to main content

No project description provided

Project description

ipydfconfig

ipydfconfig is an IPython extension to simplify per-cell dataframe display configuration.

Quickstart

  1. pip install ipydfconfig
  2. In a notebook or IPython session,
    %load_ext ipydfconfig
    
  3. For any cell in which you wish to temporarily configure a dataframe output, for polars,
    %%plconfig nr=20
    df
    
    or for pandas,
    %%pdconfig nc=50 strlen=200
    df
    

Motivation

In IPython and more commonly, Jupyter notebooks using the IPython kernel, if you wish to display a specific dataframe with more rows or columns than the default, you generally have two imperfect solutions:

Imperfect Solution 1: Modify the global configuration

pl.Config.set_tbl_rows(20)
df
pd.set_option('display.max_rows', 20)
df

The downside to this solution is that these options persist for the entire session unless you execute code to reset them, meaning they are not constrained to a particular cell.

Imperfect Solution 2: Use a context manager with display

with pl.Config(tbl_rows=20):
    display(df)
with pd.option_context('display.max_rows', 20):
    display(df)

While this solution ensures the changes are only for the specified block of code, the edits signficantly alter the structure of the code, and IPython no longer considers df as the "output" of the cell.

Configuration Option Confusion

Finally, if you use multiple dataframe modules, the differences between configuration options can require consulting documentation and/or lengthy parameter names (e.g. display.max_rows in pandas vs. tbl_rows in polars).

ipydfconfig

ipydfconfig simplifies this process by introducing cell magics that configure a cell according to the specified options that only apply to that single cell. In addition, users can use universal shortcuts that will be translated to whichever dataframe library is being used. Finally, the %%dfconfig cell magic will apply to outputs from any configured dataframe module; if an option is specific to one module, it will be ignored for the others.

There are three cell magics:

  • %%plconfig: polars
  • %%pdconfig: pandas
  • %%dfconfig: universal

In addition to all specified option names from each library (polars docs, pandas docs), ipydfconfig provides the following shortcuts that are translated to the equivalent option names:

  • nr: number of rows to display
  • rows: number of rows to display
  • nc: number of columns to display
  • cols: number of columns to display
  • strlen: maximum number of characters to show per string
  • listlen: maximum number of items to show in a list/sequence

Examples

polars
%%plconfig nr=20
df
pandas
%%pdconfig nc=50 strlen=200
df
universal
df1 = pd.read_parquet('data.parquet')
display(df1)
df2 = pl.read_parquet('data.parquet')
display(df2)

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

ipydfconfig-0.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

ipydfconfig-0.1.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ipydfconfig-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ipydfconfig-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7d0de2f9807cccf12d2b80a66a94e7165e954df8ca9e4a8a50813d02ca2c7960
MD5 71a7461260db29677b6d02382b8f69ad
BLAKE2b-256 e158827a91b5534528928a32c6e5f31dd9b84a072ceea155b14ca8546d587e5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ipydfconfig-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ipydfconfig-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 67b8f86a6c14472d2a34e8a90f5c933220b6ad4040ea6b4effb75bb59727c2c0
MD5 99306d874f8db3c528c93292b2bb79b8
BLAKE2b-256 d4994f81605f05d74cc9f228b51e7766637cafb3977fc48a2d869f685a1cd78f

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