h5typer 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.
@@ -0,0 +1,49 @@
1
+ name: Upload Python Package To Pypi
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ release:
6
+ types: [published]
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ release-build:
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v5
17
+
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.10"
21
+
22
+ - name: build release distributions
23
+ run: |
24
+ python -m pip install build
25
+ python -m build
26
+ - name: upload dists
27
+ uses: actions/upload-artifact@v4
28
+ with:
29
+ name: release-dists
30
+ path: dist/
31
+
32
+ pypi-publish:
33
+ runs-on: ubuntu-latest
34
+ needs:
35
+ - release-build
36
+ permissions:
37
+ id-token: write
38
+ environment:
39
+ name: pypi
40
+ url: https://pypi.org/p/hic-sca
41
+ steps:
42
+ - name: Retrieve release distributions
43
+ uses: actions/download-artifact@v5
44
+ with:
45
+ name: release-dists
46
+ path: dist/
47
+
48
+ - name: Publish release distributions to PyPI
49
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,105 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ *.py,cover
49
+ .hypothesis/
50
+ .pytest_cache/
51
+
52
+ # Jupyter Notebook
53
+ .ipynb_checkpoints
54
+
55
+ # IPython
56
+ profile_default/
57
+ ipython_config.py
58
+
59
+ # pyenv
60
+ .python-version
61
+
62
+ # Environments
63
+ .env
64
+ .venv
65
+ env/
66
+ venv/
67
+ ENV/
68
+ env.bak/
69
+ venv.bak/
70
+
71
+ # Spyder project settings
72
+ .spyderproject
73
+ .spyproject
74
+
75
+ # Rope project settings
76
+ .ropeproject
77
+
78
+ # mkdocs documentation
79
+ /site
80
+
81
+ # mypy
82
+ .mypy_cache/
83
+ .dmypy.json
84
+ dmypy.json
85
+
86
+ # Pyre type checker
87
+ .pyre/
88
+
89
+ # IDE settings
90
+ .vscode/
91
+ .idea/
92
+ *.swp
93
+ *.swo
94
+ *~
95
+
96
+ # OS files
97
+ .DS_Store
98
+ Thumbs.db
99
+
100
+ # Test data files
101
+ *.h5
102
+ *.hdf5
103
+
104
+ # Log files
105
+ *.log
h5typer-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Molecular Modelling and Simulation Team, iQLS, QST
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
h5typer-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,319 @@
1
+ Metadata-Version: 2.4
2
+ Name: h5typer
3
+ Version: 0.1.0
4
+ Summary: Automatic type mapping for Python objects to HDF5
5
+ Author-email: Justin Chan <chan.waisoon@qst.go.jp>, Hidetoshi Kono <kono.hidetoshi@qst.go.jp>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/iQLS-MMS/h5typer
8
+ Keywords: hdf5,type-mapping,numpy,pandas,serialization
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Scientific/Engineering
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Operating System :: OS Independent
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.19.0
23
+ Requires-Dist: pandas>=1.0.0
24
+ Requires-Dist: h5py>=3.0.0
25
+ Dynamic: license-file
26
+
27
+ # h5typer
28
+
29
+ **Automatic type mapping for Python objects to HDF5**
30
+
31
+ h5typer is a lightweight Python package that provides seamless type conversion when saving and loading nested Python dictionaries to/from HDF5 files. It automatically handles the complexity of mapping Python types (numpy arrays, pandas DataFrames/Series, None, etc.) to HDF5-compatible formats.
32
+
33
+ Originally developed as part of the [HiC-SCA](https://github.com/iQLS-MMS/hic-sca) package for Hi-C analysis, h5typer has been extracted as a standalone, reusable package that can be used in any Python project requiring HDF5 I/O with automatic type handling.
34
+
35
+ ## Features
36
+
37
+ - **Automatic Type Conversion**: Transparently handles numpy arrays, pandas DataFrames/Series, strings, None, and standard Python types
38
+ - **Nested Dictionary Support**: Save and load arbitrarily nested dictionary structures
39
+ - **Robust**: Handles edge cases like empty arrays, None values, and object dtypes
40
+ - **Simple API**: Just two main functions - `save_data()` and `load_data()`
41
+ - **Efficient**: Uses HDF5's hierarchical storage for fast I/O
42
+
43
+ ## Why h5typer?
44
+
45
+ Standard HDF5 libraries like h5py require manual handling of type conversions:
46
+
47
+ ```python
48
+ # Without h5typer - manual type handling
49
+ import h5py
50
+
51
+ with h5py.File('data.h5', 'w') as f:
52
+ f.create_dataset('array', data=np.array([1, 2, 3]))
53
+ f.create_dataset('string', data='hello'.encode('utf-8')) # Must encode
54
+ # Complex types like pandas DataFrames require custom serialization
55
+
56
+ # With h5typer - automatic!
57
+ import h5typer
58
+
59
+ data = {
60
+ 'array': np.array([1, 2, 3]),
61
+ 'string': 'hello',
62
+ 'dataframe': pd.DataFrame({'A': [1, 2]})
63
+ }
64
+ h5typer.save_data('data.h5', data)
65
+ ```
66
+
67
+ h5typer handles all the boilerplate, letting you focus on your data.
68
+
69
+ ## Installation
70
+
71
+ ```bash
72
+ # Install from source
73
+ git clone https://github.com/iQLS-MMS/h5typer.git
74
+ cd h5typer
75
+ pip install .
76
+ ```
77
+
78
+ ### Requirements
79
+
80
+ - Python >= 3.7
81
+ - numpy >= 1.19.0
82
+ - pandas >= 1.0.0
83
+ - h5py >= 3.0.0
84
+
85
+ ## Quick Start
86
+
87
+ ```python
88
+ import h5typer
89
+ import numpy as np
90
+ import pandas as pd
91
+
92
+ # Create some data
93
+ data = {
94
+ 'experiment': {
95
+ 'results': np.array([1, 2, 3, 4, 5]),
96
+ 'metadata': {
97
+ 'name': 'Test Experiment',
98
+ 'date': '2025-10-27',
99
+ 'valid': True
100
+ },
101
+ 'dataframe': pd.DataFrame({
102
+ 'A': [1, 2, 3],
103
+ 'B': [4, 5, 6]
104
+ }),
105
+ 'empty_value': None
106
+ }
107
+ }
108
+
109
+ # Save to HDF5
110
+ h5typer.save_data('output.h5', data)
111
+
112
+ # Load from HDF5
113
+ loaded_data = h5typer.load_data('output.h5')
114
+
115
+ # Access your data - it's exactly as you saved it!
116
+ print(loaded_data['experiment']['results']) # array([1, 2, 3, 4, 5])
117
+ print(loaded_data['experiment']['metadata']['name']) # 'Test Experiment'
118
+ print(loaded_data['experiment']['dataframe']) # Original DataFrame
119
+ ```
120
+
121
+ ## API Reference
122
+
123
+ ### Functions
124
+
125
+ #### `save_data(filename, data_dict, update=False)`
126
+
127
+ Save a nested dictionary to an HDF5 file.
128
+
129
+ **Parameters:**
130
+ - `filename` (str): Path to the HDF5 file
131
+ - `data_dict` (dict): Nested dictionary to save
132
+ - `update` (bool, optional): If True, update existing file; if False, overwrite. Default: False
133
+
134
+ **Example:**
135
+ ```python
136
+ import h5typer
137
+
138
+ data = {'key': 'value', 'array': np.array([1, 2, 3])}
139
+ h5typer.save_data('mydata.h5', data)
140
+
141
+ # Update existing file
142
+ more_data = {'new_key': 'new_value'}
143
+ h5typer.save_data('mydata.h5', more_data, update=True)
144
+ ```
145
+
146
+ #### `load_data(filename)`
147
+
148
+ Load a nested dictionary from an HDF5 file.
149
+
150
+ **Parameters:**
151
+ - `filename` (str): Path to the HDF5 file
152
+
153
+ **Returns:**
154
+ - `dict`: The loaded nested dictionary
155
+
156
+ **Example:**
157
+ ```python
158
+ import h5typer
159
+
160
+ data = h5typer.load_data('mydata.h5')
161
+ print(data['key']) # 'value'
162
+ ```
163
+
164
+ ### Class API
165
+
166
+ For more control, use the `H5Typer` class directly:
167
+
168
+ ```python
169
+ from h5typer import H5Typer
170
+
171
+ # Create instance
172
+ io_handler = H5Typer()
173
+
174
+ # Save data
175
+ io_handler.save_data('output.h5', my_dict)
176
+
177
+ # Load data
178
+ loaded = io_handler.load_data('output.h5')
179
+ ```
180
+
181
+ ## Supported Types
182
+
183
+ h5typer automatically handles the following Python types:
184
+
185
+ | Python Type | HDF5 Storage | Notes |
186
+ |-------------|--------------|-------|
187
+ | `numpy.ndarray` | Dataset | All dtypes supported, including object arrays |
188
+ | `pandas.DataFrame` | Group with datasets | Index, columns, and values preserved |
189
+ | `pandas.Series` | Group with datasets | Index and values preserved |
190
+ | `dict` | Group | Nested dictionaries become HDF5 groups |
191
+ | `str` | Dataset (bytes) | UTF-8 encoded |
192
+ | `int`, `float` | Dataset | Stored as numpy scalars |
193
+ | `None` | h5py.Empty | Preserved on load |
194
+ | `list`, `tuple` | Dataset | Converted to numpy arrays, all elements must be of the same type |
195
+
196
+ ## Type Conversion Details
197
+
198
+ ### NumPy Arrays
199
+
200
+ ```python
201
+ # String arrays
202
+ str_array = np.array(['a', 'b', 'c'])
203
+ # Automatically converted to bytes for HDF5
204
+
205
+ # Float64 arrays
206
+ float_array = np.array([1.0, 5.0, 3.0], dtype=np.float64)
207
+ ```
208
+
209
+ ### Pandas Objects
210
+
211
+ ```python
212
+ # DataFrames - index, columns, and values all preserved
213
+ df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
214
+
215
+ # Series - index and values preserved
216
+ series = pd.Series([1, 2, 3], index=['a', 'b', 'c'])
217
+ ```
218
+
219
+ ### None Values
220
+
221
+ ```python
222
+ data = {
223
+ 'value': None,
224
+ }
225
+ # None values are preserved through save/load
226
+ ```
227
+
228
+ ## Advanced Usage
229
+
230
+ ### Nested Structures
231
+
232
+ ```python
233
+ data = {
234
+ 'level1': {
235
+ 'level2': {
236
+ 'level3': {
237
+ 'deep_array': np.array([1, 2, 3])
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ h5typer.save_data('nested.h5', data)
244
+ loaded = h5typer.load_data('nested.h5')
245
+ # Structure is preserved
246
+ ```
247
+
248
+ ### Updating Files
249
+
250
+ ```python
251
+ # Initial save
252
+ h5typer.save_data('data.h5', {'key1': 'value1'})
253
+
254
+ # Add more data
255
+ h5typer.save_data('data.h5', {'key2': 'value2'}, update=True)
256
+
257
+ # Load gets both keys
258
+ data = h5typer.load_data('data.h5')
259
+ # {'key1': 'value1', 'key2': 'value2'}
260
+ ```
261
+
262
+ ### Integer Keys
263
+
264
+ ```python
265
+ # Integer keys are preserved
266
+ data = {
267
+ 100: 'hundred',
268
+ 200: 'two hundred',
269
+ 'string_key': 'value'
270
+ }
271
+
272
+ h5typer.save_data('intkeys.h5', data)
273
+ loaded = h5typer.load_data('intkeys.h5')
274
+ print(loaded[100]) # 'hundred' - key is still an integer
275
+ ```
276
+
277
+ ## Integration with HiC-SCA
278
+
279
+ h5typer is used by [HiC-SCA](https://github.com/iQLS-MMS/hic-sca) for all HDF5 I/O operations:
280
+
281
+ ```python
282
+ # In HiC-SCA
283
+ from hicsca import HiCSCA
284
+
285
+ # Process Hi-C data
286
+ hicsca = HiCSCA("sample.hic", resolutions=[100000])
287
+ hicsca.process_all_chromosomes()
288
+
289
+ # Save results (uses h5typer internally)
290
+ hicsca.to_hdf5("results.h5")
291
+
292
+ # Load results (uses h5typer internally)
293
+ hicsca_loaded = HiCSCA.from_hdf5("results.h5")
294
+ ```
295
+
296
+ The integration is transparent - HiC-SCA uses h5typer for automatic type mapping of complex nested dictionaries containing numpy arrays, pandas DataFrames, and metadata.
297
+
298
+ ## License
299
+
300
+ MIT License
301
+
302
+ ## Contributing
303
+
304
+ Contributions are welcome! Please feel free to submit a Pull Request.
305
+
306
+ ## Changelog
307
+
308
+ ### Version 0.1.0
309
+ - Initial release
310
+ - Support for numpy arrays, pandas DataFrames/Series, None values
311
+ - Nested dictionary support
312
+ - Integer key preservation
313
+ - Update functionality
314
+
315
+ ## See Also
316
+
317
+ - **HiC-SCA**: Hi-C Spectral Compartment Analysis package using h5typer
318
+ - **h5py**: Low-level HDF5 interface for Python
319
+ - **pandas**: Data analysis library with HDF5 support