dataset-holder 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dataset_holder-0.1.0/PKG-INFO +30 -0
- dataset_holder-0.1.0/README.md +16 -0
- dataset_holder-0.1.0/dataset_holder/__init__.py +1 -0
- dataset_holder-0.1.0/dataset_holder/dataset_holder.py +153 -0
- dataset_holder-0.1.0/dataset_holder.egg-info/PKG-INFO +30 -0
- dataset_holder-0.1.0/dataset_holder.egg-info/SOURCES.txt +9 -0
- dataset_holder-0.1.0/dataset_holder.egg-info/dependency_links.txt +1 -0
- dataset_holder-0.1.0/dataset_holder.egg-info/requires.txt +3 -0
- dataset_holder-0.1.0/dataset_holder.egg-info/top_level.txt +1 -0
- dataset_holder-0.1.0/pyproject.toml +23 -0
- dataset_holder-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dataset_holder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A central repository to hold, manage, monitor, scan, and ingest Python datasets.
|
|
5
|
+
Author-email: Your Name <your.email@example.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: pandas
|
|
12
|
+
Requires-Dist: openpyxl
|
|
13
|
+
Requires-Dist: pyarrow
|
|
14
|
+
|
|
15
|
+
# Dataset Holder
|
|
16
|
+
|
|
17
|
+
A lightweight Python library to manage, monitor, scan, and ingest data sets easily.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
```bash
|
|
21
|
+
pip install dataset_holder
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
```python
|
|
26
|
+
from dataset_holder import DatasetHolder
|
|
27
|
+
holder = DatasetHolder()
|
|
28
|
+
holder.load_file("my_data.csv")
|
|
29
|
+
print(holder.get_memory_report())
|
|
30
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Dataset Holder
|
|
2
|
+
|
|
3
|
+
A lightweight Python library to manage, monitor, scan, and ingest data sets easily.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```bash
|
|
7
|
+
pip install dataset_holder
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
```python
|
|
12
|
+
from dataset_holder import DatasetHolder
|
|
13
|
+
holder = DatasetHolder()
|
|
14
|
+
holder.load_file("my_data.csv")
|
|
15
|
+
print(holder.get_memory_report())
|
|
16
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .manager import DatasetHolder
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import pickle
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
class DatasetHolder:
|
|
8
|
+
"""A central repository to hold, manage, monitor, scan, and ingest Python datasets."""
|
|
9
|
+
|
|
10
|
+
def __init__(self):
|
|
11
|
+
self._store = {}
|
|
12
|
+
# Supported extensions and their human-readable formats
|
|
13
|
+
self._dataset_extensions = {
|
|
14
|
+
'.csv': 'Comma-Separated Values (CSV)',
|
|
15
|
+
'.xlsx': 'Excel Spreadsheet (XLSX)',
|
|
16
|
+
'.xls': 'Excel Spreadsheet (XLS)',
|
|
17
|
+
'.json': 'JSON Data File',
|
|
18
|
+
'.parquet': 'Apache Parquet',
|
|
19
|
+
'.pkl': 'Python Pickle File',
|
|
20
|
+
'.pickle': 'Python Pickle File'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def add(self, name: str, data, metadata: dict = None) -> None:
|
|
24
|
+
"""Add or overwrite a dataset in the holder."""
|
|
25
|
+
self._store[name] = {
|
|
26
|
+
"data": data,
|
|
27
|
+
"metadata": metadata or {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def get(self, name: str):
|
|
31
|
+
"""Retrieve the raw data object by name."""
|
|
32
|
+
if name not in self._store:
|
|
33
|
+
raise KeyError(f"Dataset '{name}' not found.")
|
|
34
|
+
return self._store[name]["data"]
|
|
35
|
+
|
|
36
|
+
def get_info(self, name: str) -> dict:
|
|
37
|
+
"""Retrieve metadata for a specific dataset."""
|
|
38
|
+
if name not in self._store:
|
|
39
|
+
raise KeyError(f"Dataset '{name}' not found.")
|
|
40
|
+
return self._store[name]["metadata"]
|
|
41
|
+
|
|
42
|
+
def list_datasets(self) -> list:
|
|
43
|
+
"""List all stored dataset names."""
|
|
44
|
+
return list(self._store.keys())
|
|
45
|
+
|
|
46
|
+
def remove(self, name: str) -> None:
|
|
47
|
+
"""Remove a dataset from the holder."""
|
|
48
|
+
if name in self._store:
|
|
49
|
+
del self._store[name]
|
|
50
|
+
else:
|
|
51
|
+
raise KeyError(f"Dataset '{name}' not found.")
|
|
52
|
+
|
|
53
|
+
def clear(self) -> None:
|
|
54
|
+
"""Clear all datasets."""
|
|
55
|
+
self._store.clear()
|
|
56
|
+
|
|
57
|
+
def save_to_disk(self, filepath: str) -> None:
|
|
58
|
+
"""Save the entire dataset holder to a file."""
|
|
59
|
+
with open(filepath, 'wb') as f:
|
|
60
|
+
pickle.dump(self._store, f)
|
|
61
|
+
print(f"Successfully saved {len(self._store)} dataset(s) to {filepath}")
|
|
62
|
+
|
|
63
|
+
def load_from_disk(self, filepath: str) -> None:
|
|
64
|
+
"""Load datasets from a file, merging or overwriting current datasets."""
|
|
65
|
+
path = Path(filepath)
|
|
66
|
+
if not path.exists():
|
|
67
|
+
raise FileNotFoundError(f"No file found at {filepath}")
|
|
68
|
+
|
|
69
|
+
with open(filepath, 'rb') as f:
|
|
70
|
+
loaded_store = pickle.load(f)
|
|
71
|
+
|
|
72
|
+
self._store.update(loaded_store)
|
|
73
|
+
print(f"Successfully loaded {len(loaded_store)} dataset(s) from {filepath}")
|
|
74
|
+
|
|
75
|
+
def _calculate_size(self, data) -> int:
|
|
76
|
+
"""Helper method to accurately calculate memory size in bytes."""
|
|
77
|
+
# Use deep evaluation if it is a Pandas object to catch object/string column sizes
|
|
78
|
+
if hasattr(data, 'memory_usage'):
|
|
79
|
+
return int(data.memory_usage(deep=True).sum())
|
|
80
|
+
return sys.getsizeof(data)
|
|
81
|
+
|
|
82
|
+
def get_memory_report(self) -> dict:
|
|
83
|
+
"""Returns a breakdown of memory usage for all stored datasets."""
|
|
84
|
+
report = {}
|
|
85
|
+
total_bytes = 0
|
|
86
|
+
for name, content in self._store.items():
|
|
87
|
+
size_bytes = self._calculate_size(content["data"])
|
|
88
|
+
total_bytes += size_bytes
|
|
89
|
+
report[name] = self._format_size(size_bytes)
|
|
90
|
+
report["TOTAL_LIBRARY_SIZE"] = self._format_size(total_bytes)
|
|
91
|
+
return report
|
|
92
|
+
|
|
93
|
+
def _format_size(self, size_bytes: int) -> str:
|
|
94
|
+
"""Helper method to format bytes into KB, MB, or GB."""
|
|
95
|
+
for unit in ['Bytes', 'KB', 'MB', 'GB']:
|
|
96
|
+
if size_bytes < 1024:
|
|
97
|
+
return f"{size_bytes:.2f} {unit}"
|
|
98
|
+
size_bytes /= 1024
|
|
99
|
+
return f"{size_bytes:.2f} TB"
|
|
100
|
+
|
|
101
|
+
def scan_directory(self, folder_path: str) -> dict:
|
|
102
|
+
"""Scans a directory and identifies which files are valid datasets."""
|
|
103
|
+
path = Path(folder_path)
|
|
104
|
+
if not path.exists() or not path.is_dir():
|
|
105
|
+
raise NotADirectoryError(f"'{folder_path}' is not a valid directory.")
|
|
106
|
+
|
|
107
|
+
results = {"datasets_found": {}, "total_datasets_count": 0}
|
|
108
|
+
|
|
109
|
+
for file in path.iterdir():
|
|
110
|
+
if file.is_file():
|
|
111
|
+
ext = file.suffix.lower()
|
|
112
|
+
if ext in self._dataset_extensions:
|
|
113
|
+
results["datasets_found"][file.name] = {
|
|
114
|
+
"type": self._dataset_extensions[ext],
|
|
115
|
+
"file_size": self._format_size(file.stat().st_size),
|
|
116
|
+
"full_path": str(file.resolve())
|
|
117
|
+
}
|
|
118
|
+
results["total_datasets_count"] += 1
|
|
119
|
+
return results
|
|
120
|
+
|
|
121
|
+
def load_file(self, file_path: str, dataset_name: str = None) -> None:
|
|
122
|
+
"""Automatically reads a single dataset file into memory based on its extension."""
|
|
123
|
+
path = Path(file_path)
|
|
124
|
+
if not path.exists():
|
|
125
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
126
|
+
|
|
127
|
+
ext = path.suffix.lower()
|
|
128
|
+
name = dataset_name or path.stem
|
|
129
|
+
metadata = {"source_file": str(path.resolve()), "file_type": ext}
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
if ext == '.csv':
|
|
133
|
+
data = pd.read_csv(path)
|
|
134
|
+
elif ext in ['.xlsx', '.xls']:
|
|
135
|
+
data = pd.read_excel(path)
|
|
136
|
+
elif ext == '.parquet':
|
|
137
|
+
data = pd.read_parquet(path)
|
|
138
|
+
elif ext in ['.pkl', '.pickle']:
|
|
139
|
+
with open(path, 'rb') as f:
|
|
140
|
+
data = pickle.load(f)
|
|
141
|
+
elif ext == '.json':
|
|
142
|
+
with open(path, 'r', encoding='utf-8') as f:
|
|
143
|
+
data = json.load(f)
|
|
144
|
+
else:
|
|
145
|
+
raise ValueError(f"Unsupported file format: {ext}")
|
|
146
|
+
|
|
147
|
+
self.add(name, data, metadata=metadata)
|
|
148
|
+
print(f"Successfully ingested dataset '{name}' into library.")
|
|
149
|
+
|
|
150
|
+
except json.JSONDecodeError:
|
|
151
|
+
print(f"Error: '{name}' is not a valid JSON file. It might be empty or formatted incorrectly.")
|
|
152
|
+
except Exception as e:
|
|
153
|
+
print(f"Failed to read dataset '{name}': {e}")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dataset_holder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A central repository to hold, manage, monitor, scan, and ingest Python datasets.
|
|
5
|
+
Author-email: Your Name <your.email@example.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: pandas
|
|
12
|
+
Requires-Dist: openpyxl
|
|
13
|
+
Requires-Dist: pyarrow
|
|
14
|
+
|
|
15
|
+
# Dataset Holder
|
|
16
|
+
|
|
17
|
+
A lightweight Python library to manage, monitor, scan, and ingest data sets easily.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
```bash
|
|
21
|
+
pip install dataset_holder
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
```python
|
|
26
|
+
from dataset_holder import DatasetHolder
|
|
27
|
+
holder = DatasetHolder()
|
|
28
|
+
holder.load_file("my_data.csv")
|
|
29
|
+
print(holder.get_memory_report())
|
|
30
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
dataset_holder/__init__.py
|
|
4
|
+
dataset_holder/dataset_holder.py
|
|
5
|
+
dataset_holder.egg-info/PKG-INFO
|
|
6
|
+
dataset_holder.egg-info/SOURCES.txt
|
|
7
|
+
dataset_holder.egg-info/dependency_links.txt
|
|
8
|
+
dataset_holder.egg-info/requires.txt
|
|
9
|
+
dataset_holder.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dataset_holder
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dataset_holder"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Your Name", email="your.email@example.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "A central repository to hold, manage, monitor, scan, and ingest Python datasets."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"pandas",
|
|
21
|
+
"openpyxl",
|
|
22
|
+
"pyarrow",
|
|
23
|
+
]
|