Skip to content

Commit cee5439

Browse files
committed
.
1 parent af012b1 commit cee5439

6 files changed

Lines changed: 122 additions & 91 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ jobs:
1919

2020
- uses: astral-sh/ruff-action@v3
2121
with:
22-
version: 0.14.8
22+
args: format --check
23+
24+
- uses: astral-sh/ruff-action@v3
25+
with:
2326
args: check --output-format=github
2427

2528

@@ -42,19 +45,14 @@ jobs:
4245

4346
steps:
4447
- uses: actions/checkout@v4
45-
- uses: actions/setup-python@v5
46-
with:
47-
python-version: ${{ matrix.python-version }}
48-
4948
- name: Setup uv
50-
uses: astral-sh/setup-uv@v1
51-
with:
52-
# Cache dependencies installed by uv
53-
cache: true
49+
uses: astral-sh/setup-uv@v5
50+
51+
- name: Set up Python ${{ matrix.python-version }}
52+
run: uv python install ${{ matrix.python-version }}
5453

55-
- name: Install and test
54+
- name: Install dependencies and test
5655
run: |
57-
uv venv
58-
uv pip install -e .[dev]
56+
uv sync --dev
5957
uv run pytest
6058

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OMX Python API Documentation
22

3-
The Python OMX API borrows heavily from PyTables. An OMX file extends the equivalent PyTables File object, so anything you can do in PyTables you can do with OMX as well. This API attempts to be very Pythonic, including dictionary-style lookup of matrix names.
3+
The Python OMX API is built on top of h5py. An OMX file extends the equivalent h5py File object, so anything you can do in h5py you can do with OMX as well. This API attempts to be very Pythonic, including dictionary-style lookup of matrix names.
44

55
* [Pre-requisites](#pre-requisites)
66
* [Installation](#installation)
@@ -12,7 +12,7 @@ The Python OMX API borrows heavily from PyTables. An OMX file extends the equiva
1212

1313
# Pre-requisites
1414

15-
Python 3.10+, h5py 3.0+, and NumPy.
15+
Python 3.9+, h5py 2.10+, and NumPy.
1616

1717
Binaries for all these dependencies are readily available from PyPI and can be installed via pip.
1818

@@ -153,15 +153,14 @@ will call createMatrix() for you and populate it with the specified array.
153153

154154
### Accessing Data
155155

156-
You can access matrix objects by name, using dictionary lookup e.g. `myfile['hwydist']` or using PyTables path notation, e.g. `myfile.root.hwydist`
156+
You can access matrix objects by name, using dictionary lookup e.g. `myfile['hwydist']`.
157157

158158
### Matrix objects
159159

160-
OMX matrices extend numpy arrays. An OMX matrix object extends a Pytables/HDF5 "node" which means all HDF5 methods and properties behave normally. Generally these datasets are going to be numpy CArray objects of arbitrary shape.
160+
OMX matrices are h5py Dataset objects. An OMX matrix object extends an h5py Dataset which means all h5py methods and properties behave normally.
161161
You can access a matrix object by name using:
162162

163163
* dictionary syntax, e.g. `myfile['hwydist']`
164-
* or by Pytables path syntax, e.g. `myfile.root.hwydist`
165164

166165
Once you have a matrix object, you can perform normal numpy math on it or you can access rows and columns pythonically:
167166

@@ -207,7 +206,7 @@ OMX module version string. Currently '0.3.5' as of this writing. This is the Py
207206
### `__omx_version__`
208207
OMX file format version. Currently '0.2'. This is the OMX file format specification that omx-python adheres to.
209208

210-
### `open_file`(filename, mode='r', title='', root_uep='/', filters=Filters(complevel=1, complib='zlib', shuffle=True, bitshuffle=False, fletcher32=False, least_significant_digit=None), shape=None, **kwargs)
209+
### `open_file`(filename, mode='r', title='', filters=None, shape=None, **kwargs)
211210
Open or create a new OMX file. New files will be created with default
212211
zlib compression enabled.
213212
@@ -223,7 +222,7 @@ OMX file format version. Currently '0.2'. This is the OMX file format specificat
223222
title : string
224223
Short description of this file, used when creating the file. Default is ''.
225224
Ignored in read-only mode.
226-
filters : tables.Filters
225+
filters : dict
227226
HDF5 default filter options for compression, shuffling, etc. Default for
228227
OMX standard file format is: zlib compression level 1, and shuffle=True.
229228
Only specify this if you want something other than the recommended standard
@@ -263,46 +262,48 @@ OMX file format version. Currently '0.2'. This is the OMX file format specificat
263262
264263
Returns:
265264
--------
266-
mapping : tables.array
265+
mapping : h5py.Dataset
267266
Returns the created mapping.
268267
269268
Raises:
270269
LookupError : if the mapping exists and overwrite=False
271270

272-
### `create_matrix`(self, name, atom=None, shape=None, title='', filters=None, chunkshape=None, byteorder=None, createparents=False, obj=None, attrs=None)
273-
Create an OMX Matrix (CArray) at the root level. User must pass in either
274-
an existing numpy matrix, or a shape and an atom type.
271+
### `create_matrix`(self, name, shape=None, title='', filters=None, chunks=True, obj=None, dtype=None, attrs=None)
272+
Create an OMX Matrix (Dataset) at the root level. User must pass in either
273+
an existing numpy matrix, or a shape and a dtype.
275274
276275
Parameters
277276
----------
278277
name : string
279278
The name of this matrix. Stored in HDF5 as the leaf name.
280279
title : string
281280
Short description of this matrix. Default is ''.
282-
obj : numpy.CArray
281+
obj : numpy.ndarray
283282
Existing numpy array from which to create this OMX matrix. If obj is passed in,
284-
then shape and atom can be left blank. If obj is not passed in, then a shape and
285-
atom must be specified instead. Default is None.
283+
then shape and dtype can be left blank. If obj is not passed in, then a shape and
284+
dtype must be specified instead. Default is None.
286285
shape : numpy.array
287286
Optional shape of the matrix. Shape is an int32 numpy array of format (rows,columns).
288-
If shape is not specified, an existing numpy CArray must be passed in instead,
287+
If shape is not specified, an existing numpy array must be passed in instead,
289288
as the 'obj' parameter. Default is None.
290-
atom : atom_type
291-
Optional atom type of the data. Can be int32, float32, etc. Default is None.
289+
dtype : dtype
290+
Optional data type of the data. Can be 'int32', 'float32', etc. Default is None.
292291
If None specified, then obj parameter must be passed in instead.
293-
filters : tables.Filters
292+
filters : dict
294293
Set of HDF5 filters (compression, etc) used for creating the matrix.
295294
Default is None. See HDF5 documentation for details. Note: while the default here
296295
is None, the default set of filters set at the OMX parent file level is
297296
zlib compression level 1. Those settings usually trickle down to the table level.
297+
chunks : tuple or bool
298+
Chunk shape, or True to enable auto-chunking. Default is True.
298299
attrs : dict
299300
Dictionary of attribute names and values to be attached to this matrix.
300301
Default is None.
301302
302303
Returns
303304
-------
304-
matrix : tables.carray
305-
HDF5 CArray matrix
305+
matrix : h5py.Dataset
306+
HDF5 Dataset matrix
306307

307308
### `delete_mapping`(self, title)
308309
Remove a mapping.

openmatrix/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def open_file(filename, mode="r", title="", filters=None, shape=None, **kwargs):
4949
if filters is None and mode != "r":
5050
filters = {"complib": "zlib", "complevel": 1, "shuffle": True}
5151

52-
f = File(filename, mode, title=title, **kwargs)
52+
f = File(filename, mode, title=title, filters=filters, **kwargs)
5353

5454
# add omx structure if file is writable
5555
if mode != "r":
@@ -61,7 +61,7 @@ def open_file(filename, mode="r", title="", filters=None, shape=None, **kwargs):
6161

6262
# shape
6363
if shape:
64-
storeshape = np.zeros([shape[0], shape[1]], dtype=np.int32)
64+
storeshape = np.array([shape[0], shape[1]], dtype=np.int32)
6565
f.attrs["SHAPE"] = storeshape
6666

6767
# /data and /lookup folders

openmatrix/file.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ class File(h5py.File):
1212
and mappings in an OMX file.
1313
"""
1414

15-
def __init__(self, name, mode="r", title="", **kwargs):
15+
def __init__(self, name, mode="r", title="", filters=None, **kwargs):
1616
super(File, self).__init__(name, mode, **kwargs)
1717
self._shape = None
18+
self.default_filters = filters
1819

1920
def version(self):
2021
"""
@@ -53,18 +54,23 @@ def create_matrix(self, name, shape=None, title="", filters=None, chunks=True, o
5354

5455
# If filters is passed (it might be a tables.Filters object or a dict or None)
5556
# We'll try to parse basic stuff or just use defaults if it's the standard OMX one
57+
filters = filters or self.default_filters
58+
5659
if filters:
57-
if hasattr(filters, "complib"):
58-
if filters.complib == "zlib":
59-
compression = "gzip"
60-
elif filters.complib:
61-
compression = filters.complib
60+
# Handle dict
61+
if isinstance(filters, dict):
62+
compression = filters.get("complib")
63+
compression_opts = filters.get("complevel")
64+
shuffle = filters.get("shuffle")
65+
66+
# Handle object with attributes (like tables.Filters)
67+
elif hasattr(filters, "complib"):
68+
compression = filters.complib if filters.complib else compression
69+
compression_opts = filters.complevel if hasattr(filters, "complevel") else compression_opts
70+
shuffle = filters.shuffle if hasattr(filters, "shuffle") else shuffle
6271

63-
if hasattr(filters, "complevel"):
64-
compression_opts = filters.complevel
65-
if hasattr(filters, "shuffle"):
66-
shuffle = filters.shuffle
6772

73+
compression = "gzip" if compression == "zlib" else compression
6874
# Defaults if not specified but standard in OMX (zlib 1)
6975
# Actually tables default in __init__ was passed.
7076
# h5py doesn't have a default file-wide filter.

0 commit comments

Comments
 (0)