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)
Release files for hydrotools.caches 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hydrotools_caches-0.1.5.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hydrotools.caches-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:10.5 kB
Release files / hydrotools_caches-0.1.5.tar.gz
| Download URL | hydrotools_caches-0.1.5.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a5d270f187d56cede7190d3c0f901bc89c8f37c4da4d1564340fd45138f62ff
|
|
BLAKE2b-256 checksum How to use checksums |
6035b858e3fdbc9c7765974a61507dd97b7ba1775828a8dc0865269754a7d26d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.2
|
Release files / hydrotools.caches-0.1.5-py3-none-any.whl
| Download URL | hydrotools.caches-0.1.5-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6de74f0818f2756ee5a4704343e9329a94913aa82bc09e121e7e80b13643aa5e
|
|
BLAKE2b-256 checksum How to use checksums |
5069f2e928023feb71121827c8a43736b87aab9d83426eecaae642b7d8f06fb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.2
|