Skip to main content

Tidy saving and loading of Numpy and Pandas object attributes

Project description

zipdist

Keeping NumPy and Pandas attributes of python classes nice and tidy

Build Status Coverage Status PyPI version

The Zipdist2 class provides methods for saving and reloading NumPy arrays and Pandas DataFrame object attributes.

Complex attributes are saved to a single .tar.gz file.

The contents of the .tar.gz provides a tidy human-readable record of Pandas and Numpy Python class attributes as .csv and binary files.

Install

pip install zipdist==0.1.3

Basic Example

from zipdist.zip2 import Zipdist2
import pandas as pd
import numpy as np
import os

class X():
	def __init__(self, name):
		self.name = name

x = X(name = 'example_target_object')
x.example_simple_attr = [1989, 2020]
x.example_np_attr = np.array([[0, 1, 2, 3], [4, 5, 6, 7]])
x.example_pd_attr  = pd.DataFrame({"A":[1,2,3], "B":[2,4,6]})

z = Zipdist2(name = "zipper", target = x)
z._save(dest = "archive", dest_tar = "archive.tar.gz")
assert os.path.isfile("archive.tar.gz")
Saving example_np_attr to .csv : archive/example_np_attr.csv
Saving example_np_attr to .npy : archive/example_np_attr.npy
Saving example_pd_attr to .csv : archive/example_pd_attr.csv
Saving example_pd_attr to .feather : archive/example_pd_attr.feather
Saving JSON with complex attribute definitions : archive/complex_attributes.json
Saving JSON with simple attribute definitions : archive/simple_attributes.json
Combining saved files in : [archive.tar.gz].

Contents of archive.tar.gz

archive
├── complex_attributes.json
├── example_np_attr.csv
├── example_np_attr.npy
├── example_pd_attr.csv
├── example_pd_attr.feather
└── simple_attributes.json

Reload All Attributes of a Target Object with ._build()

x_new = X(name = 'example_target_object')
z = Zipdist2(name = "zipper", target = x_new)
# You can use the z._build() and reload all object attributes
z._build(target = x_new, dest = "archive", dest_tar = "archive.tar.gz")
Setting simple attribute name to example_target_object
Setting simple attribute example_simple_attr to [1989, 2020]
Setting [npy] to [np.ndarray] for attribute example_np_attr from: example_np_attr.npy
Setting [feather] to [pd.DataFrame] for attribute example_pd_attr from: example_pd_attr.feather

For instance:

>>>	x_new.example_simple_attr:
[1989, 2020]
>>>	x_new.example_np_attr:
[[0 1 2 3]
 [4 5 6 7]]
>>>	x_new.example_pd_attr:
   A  B
0  1  2
1  2  4
2  3  6

Reload Simple and Complex Object Attributes One by One with ._ready(), _reload_simple(), and _reload_complex().

# You can alternatively use the z._ready() and reload object attributes one by one
x_new = X(name = 'example_target_object')
z = Zipdist2(name = "zipper", target = x_new)
z._ready(target = x_new, dest = "archive", dest_tar = "archive.tar.gz")
z._reload_complex(k='example_np_attr')
z._reload_simple(k='example_simple_attr')

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

zipdist-0.1.5.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

zipdist-0.1.5-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file zipdist-0.1.5.tar.gz.

File metadata

  • Download URL: zipdist-0.1.5.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.3

File hashes

Hashes for zipdist-0.1.5.tar.gz
Algorithm Hash digest
SHA256 78185d2c01253f8c911a0f6d6a924a8622b0a0d3db351e04c093c956e823f262
MD5 cd9f3064217564b520f24633231c91f2
BLAKE2b-256 ddab8e3789d6780e54e3af9568d76430c5a7934cd51e11c247fea98b65ebba36

See more details on using hashes here.

File details

Details for the file zipdist-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: zipdist-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.3

File hashes

Hashes for zipdist-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cb65d12c6ca504596bbd803397bc262958c00506a81d9874735231f1f2133285
MD5 c12a022fcb33b29e5a0f199927f54dd7
BLAKE2b-256 caa72c4907e3f5389664c67e533286c77c69a1b005bd112dee5488f7bfb8ee66

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page