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

Uploaded Source

Built Distribution

zipdist-0.1.4-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zipdist-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 28371fda354245671665740705ff999614cc09b70ac44ae0ea5c2f0e258f2060
MD5 ab2ff4d33679906ab52df931c7effb1e
BLAKE2b-256 9692a8d6e6638d44502d492824b110ca6925572089262c151a2c8635501fa63c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zipdist-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 18.1 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cc23074722f935545a759cf0d8880cac43d2a0366344730565599d03df006b2f
MD5 59bb378457fc5beb17a9598597e944e1
BLAKE2b-256 e4de9eba8629a0558d7d05aab4ecf318b203e1a56047752949433c350dc52f22

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