Skip to content

pandas_openscm#

Pandas accessors for OpenSCM-related functionality.

Modules:

Name Description
accessors

API for pandas accessors.

comparison

Tools that support comparisons between pd.DataFrame's

db

Database

exceptions

Exceptions that are used throughout

grouping

Support for grouping in various ways

index_manipulation

Manipulation of the index of data

indexing

Helpers for working with pandas

io

Serialisation/deserialisation (i.e. input/output) support

parallelisation

Parallelisation helpers

plotting

Plotting

reshaping

Tools for reshaping data in common ways

testing

Testing helpers

typing

Type hints that are used throughout

unit_conversion

Support for unit conversion

Functions:

Name Description
register_pandas_accessors

Register the pandas accessors

register_pandas_accessors #

register_pandas_accessors(
    namespace: str = "openscm",
) -> None

Register the pandas accessors

This registers accessors for DataFrame's, Series's and Index's. If you only want to register accessors for one of these, we leave it up to you to copy the line(s) you need.

For details of how these accessors work, see pandas' docs.

We provide this as a separate function because we have had really bad experiences with imports having side effects (which seems to be the more normal pattern) and don't want to pass those bad experiences on.

Parameters:

Name Type Description Default
namespace str

Namespace to use for the accessor

E.g. if namespace is 'custom' then the pandas-openscm API will be available under pd.DataFrame.custom.pandas_openscm_function e.g. pd.DataFrame.custom.convert_unit.

'openscm'
Source code in src/pandas_openscm/accessors/__init__.py
def register_pandas_accessors(namespace: str = "openscm") -> None:
    """
    Register the pandas accessors

    This registers accessors
    for [DataFrame][pandas.DataFrame]'s, [Series][pandas.Series]'s
    and [Index][pandas.Index]'s.
    If you only want to register accessors for one of these,
    we leave it up to you to copy the line(s) you need.

    For details of how these accessors work, see
    [pandas' docs](https://pandas.pydata.org/docs/development/extending.html#registering-custom-accessors).

    We provide this as a separate function
    because we have had really bad experiences with imports having side effects
    (which seems to be the more normal pattern)
    and don't want to pass those bad experiences on.

    Parameters
    ----------
    namespace
        Namespace to use for the accessor

        E.g. if namespace is 'custom'
        then the pandas-openscm API will be available under
        `pd.DataFrame.custom.pandas_openscm_function`
        e.g. `pd.DataFrame.custom.convert_unit`.
    """
    pd.api.extensions.register_dataframe_accessor(namespace)(
        PandasDataFrameOpenSCMAccessor
    )
    pd.api.extensions.register_series_accessor(namespace)(PandasSeriesOpenSCMAccessor)
    pd.api.extensions.register_index_accessor(namespace)(PandasIndexOpenSCMAccessor)