hashable_ndframes

Hashable (pandas) Series and DataFrames.


Keywords
hashable, pandas, series, dataframe
License
MIT
Install
pip install hashable_ndframes==0.1.3

Documentation

hashable_ndframes

PyPI PyPI - Python Version Build Status

Overview

hashable_ndframes provides subclasses HashableSeries and HashableDataFrame (of pandas.Series and pandas.DataFrame, respectively) which are hashable.

Examples

from pandas import Series
from hashable_ndframes import HashableSeries

# Series
s = HashableSeries(["a", "b", "c"])
assert isinstance(s, Series)

# equal Series, equal hash
hs = hash(s)
assert hash(HashableSeries(["a", "b", "c"])) == hs

# unequal Series, unequal hash
assert hash(HashableSeries(["a", "z", "c"])) != hs
assert hash(HashableSeries(["a", "b", "c"], name="other_name")) != hs

Motivation

This was motivated by the need to cache expensive computations, but since pandas.Series and pandas.DataFrames are unhashable, they will not work with functools.lru_cache. If you need this functionality, then you can check out hashable_lru_cache and apply @hashable_lru_cache(transforms={Series: HashableSeries, DataFrame: HashableDataFrame})