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.3.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

zipdist-0.1.3-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zipdist-0.1.3.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for zipdist-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0cd4550406fcd7e3de1009e9d5ad7fc746d5cfd097895f5144f0436b515a54bd
MD5 1a673ecb636e30cdf6c95b0b05664bcd
BLAKE2b-256 c9953dab3369aa83b1d222d055b35679929d801f46f103081135418e5226115b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zipdist-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for zipdist-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c3d1aaa3d1020c9ffe893b97b6cf20c30f58cf92d8dd41c97d99cb3e569204c4
MD5 113c36aa9bbbd29554cb02672637dc29
BLAKE2b-256 b0ec0635dddfd53e37e00df352710812a5ca0c3bed7fc830602f8cefb36d0ca3

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