Variety of object caching utilities for OWPHydroTools.
Project description
OWPHydroTools :: Caches
This subpackage implements different methods to cache objects generated by hydrotools
methods. See the Caches Documentation for a complete list and description of the currently available caches. To report bugs or request additional features, submit an issue through the OWPHydroTools Issue Tracker on GitHub.
Installation
In accordance with the python community, we support and advise the usage of virtual environments in any workflow using python. In the following installation guide, we use python's built-in venv
module to create a virtual environment in which the tool will be installed. Note this is just personal preference, any python virtual environment manager should work just fine (conda
, pipenv
, etc. ).
# Create and activate python environment, requires python >= 3.8
$ python3 -m venv venv
$ source venv/bin/activate
$ python3 -m pip install --upgrade pip
# Install caches
$ python3 -m pip install hydrotools.caches
Mac Silicon Note
If you experience issues installing the tables
library while installing
hydrotools.caches
, you likely need to install HDF5
and/or set the HDF5_DIR
environement variable prior to installation. Brew users should install
HDF5
using brew install hdf5
and try reinstalling hydrotools.caches
using
env HDF5_DIR=$(brew --prefix hdf5) pip install hydrotools.caches
. If you've
already installed HDF5
via brew, ignore the first step.
Usage
The following example demonstrates how one might use hydrotools.caches.hdf
to cache a pandas.dataframe
generated by a long running process.
Code
from hydrotools.caches.hdf import HDFCache
import pandas as pd
from time import sleep
# Some long running process that returns a pandas.DataFrame
def long_process(cols, rows):
sleep(1.0)
data = {f'col_{i}' : [j for j in range(rows)] for i in range(cols)}
return pd.DataFrame(data)
# Setup the cache with a context manager
# Similar to setting up a pandas.HDFStore
with HDFCache(
path='mycache.h5',
complevel=1,
complib='zlib',
fletcher32=True
) as cache:
# The first call runs long_process and stores the result
df = cache.get(long_process, 'data/results', cols=10, rows=1000000)
# The second call retrieves the result from cache without
# running long_process
df = cache.get(long_process, 'data/results', cols=10, rows=1000000)
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
Built Distribution
File details
Details for the file hydrotools_caches-0.1.5.tar.gz
.
File metadata
- Download URL: hydrotools_caches-0.1.5.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
5a5d270f187d56cede7190d3c0f901bc89c8f37c4da4d1564340fd45138f62ff
|
|
MD5 |
47392bccf043991d0cf3c490b6ffbded
|
|
BLAKE2b-256 |
6035b858e3fdbc9c7765974a61507dd97b7ba1775828a8dc0865269754a7d26d
|
File details
Details for the file hydrotools.caches-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: hydrotools.caches-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
6de74f0818f2756ee5a4704343e9329a94913aa82bc09e121e7e80b13643aa5e
|
|
MD5 |
02a01b7fb96561801e3f0441a9b51af5
|
|
BLAKE2b-256 |
5069f2e928023feb71121827c8a43736b87aab9d83426eecaae642b7d8f06fb3
|