Skip to content

Commit afa2414

Browse files
committed
[feat, refactor] refactor dtype map to use Enum DTypes. Implemented constrained dataset. Datastore.model_dump_hdf5 default mode changed to "w".
1 parent 0bc7790 commit afa2414

File tree

6 files changed

+225
-148
lines changed

6 files changed

+225
-148
lines changed

examples/custom_group.ipynb

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 7,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -11,7 +11,7 @@
1111
"import numpy as np\n",
1212
"from rich.pretty import pprint\n",
1313
"\n",
14-
"from oqd_dataschema.base import Dataset, GroupBase, GroupRegistry\n",
14+
"from oqd_dataschema.base import Dataset, GroupBase, GroupRegistry, condataset\n",
1515
"from oqd_dataschema.datastore import Datastore\n",
1616
"from oqd_dataschema.groups import (\n",
1717
" SinaraRawDataGroup,\n",
@@ -20,21 +20,30 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 2,
23+
"execution_count": 8,
2424
"metadata": {},
25-
"outputs": [],
25+
"outputs": [
26+
{
27+
"name": "stderr",
28+
"output_type": "stream",
29+
"text": [
30+
"D:\\work\\Projects\\oqd-dataschema\\src\\oqd_dataschema\\base.py:265: UserWarning: Overwriting previously registered `YourCustomGroup` group of the same name.\n",
31+
" GroupRegistry.register(cls)\n"
32+
]
33+
}
34+
],
2635
"source": [
2736
"class YourCustomGroup(GroupBase):\n",
2837
" \"\"\"\n",
2938
" Here we define a custom Group, which is automatically added at runtime to the GroupRegistry.\n",
3039
" \"\"\"\n",
3140
"\n",
32-
" array: Dataset"
41+
" array: condataset(shape_constraint=(None, 10)) # type: ignore"
3342
]
3443
},
3544
{
3645
"cell_type": "code",
37-
"execution_count": 3,
46+
"execution_count": 9,
3847
"metadata": {},
3948
"outputs": [
4049
{
@@ -47,7 +56,7 @@
4756
" 'YourCustomGroup': __main__.YourCustomGroup}"
4857
]
4958
},
50-
"execution_count": 3,
59+
"execution_count": 9,
5160
"metadata": {},
5261
"output_type": "execute_result"
5362
}
@@ -58,7 +67,7 @@
5867
},
5968
{
6069
"cell_type": "code",
61-
"execution_count": 4,
70+
"execution_count": 10,
6271
"metadata": {},
6372
"outputs": [],
6473
"source": [
@@ -73,7 +82,7 @@
7382
},
7483
{
7584
"cell_type": "code",
76-
"execution_count": 5,
85+
"execution_count": 11,
7786
"metadata": {},
7887
"outputs": [
7988
{
@@ -119,7 +128,8 @@
119128
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ │ </span><span style=\"font-weight: bold\">)</span>,\n",
120129
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ │ </span><span style=\"color: #808000; text-decoration-color: #808000\">class_</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'YourCustomGroup'</span>\n",
121130
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ </span><span style=\"font-weight: bold\">)</span>\n",
122-
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\">}</span>\n",
131+
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\">}</span>,\n",
132+
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"color: #808000; text-decoration-color: #808000\">attrs</span>=<span style=\"font-weight: bold\">{}</span>\n",
123133
"<span style=\"font-weight: bold\">)</span>\n",
124134
"</pre>\n"
125135
],
@@ -164,7 +174,8 @@
164174
"\u001b[2;32m│ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n",
165175
"\u001b[2;32m│ │ │ \u001b[0m\u001b[33mclass_\u001b[0m=\u001b[32m'YourCustomGroup'\u001b[0m\n",
166176
"\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n",
167-
"\u001b[2;32m│ \u001b[0m\u001b[1m}\u001b[0m\n",
177+
"\u001b[2;32m│ \u001b[0m\u001b[1m}\u001b[0m,\n",
178+
"\u001b[2;32m│ \u001b[0m\u001b[33mattrs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m\n",
168179
"\u001b[1m)\u001b[0m\n"
169180
]
170181
},
@@ -184,7 +195,7 @@
184195
},
185196
{
186197
"cell_type": "code",
187-
"execution_count": 6,
198+
"execution_count": 12,
188199
"metadata": {},
189200
"outputs": [
190201
{
@@ -230,7 +241,8 @@
230241
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ │ </span><span style=\"font-weight: bold\">)</span>,\n",
231242
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ │ </span><span style=\"color: #808000; text-decoration-color: #808000\">class_</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'YourCustomGroup'</span>\n",
232243
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ │ </span><span style=\"font-weight: bold\">)</span>\n",
233-
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\">}</span>\n",
244+
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"font-weight: bold\">}</span>,\n",
245+
"<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│ </span><span style=\"color: #808000; text-decoration-color: #808000\">attrs</span>=<span style=\"font-weight: bold\">{}</span>\n",
234246
"<span style=\"font-weight: bold\">)</span>\n",
235247
"</pre>\n"
236248
],
@@ -275,7 +287,8 @@
275287
"\u001b[2;32m│ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n",
276288
"\u001b[2;32m│ │ │ \u001b[0m\u001b[33mclass_\u001b[0m=\u001b[32m'YourCustomGroup'\u001b[0m\n",
277289
"\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n",
278-
"\u001b[2;32m│ \u001b[0m\u001b[1m}\u001b[0m\n",
290+
"\u001b[2;32m│ \u001b[0m\u001b[1m}\u001b[0m,\n",
291+
"\u001b[2;32m│ \u001b[0m\u001b[33mattrs\u001b[0m=\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m\n",
279292
"\u001b[1m)\u001b[0m\n"
280293
]
281294
},
@@ -287,13 +300,6 @@
287300
"parse = Datastore.model_validate_hdf5(filepath)\n",
288301
"pprint(parse)"
289302
]
290-
},
291-
{
292-
"cell_type": "code",
293-
"execution_count": null,
294-
"metadata": {},
295-
"outputs": [],
296-
"source": []
297303
}
298304
],
299305
"metadata": {

pyproject.toml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ classifiers = [
2626
"Programming Language :: Python :: 3.12",
2727
]
2828

29-
dependencies = [
30-
"bidict>=0.23.1",
31-
"h5py>=3.13.0",
32-
"pydantic>=2.10.6",
33-
]
29+
dependencies = ["h5py>=3.14.0", "pydantic>=2.10.6"]
3430

3531
[project.optional-dependencies]
3632
docs = [
@@ -52,12 +48,7 @@ select = ["E4", "E7", "E9", "F", "I"]
5248
fixable = ["ALL"]
5349

5450
[dependency-groups]
55-
dev = [
56-
"jupyter>=1.1.1",
57-
"pre-commit>=4.1.0",
58-
"rich>=14.1.0",
59-
"ruff>=0.13.1",
60-
]
51+
dev = ["jupyter>=1.1.1", "pre-commit>=4.1.0", "rich>=14.1.0", "ruff>=0.13.1"]
6152

6253

6354
[project.urls]

src/oqd_dataschema/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .base import Dataset, GroupBase, GroupRegistry
15+
from .base import Dataset, GroupBase, GroupRegistry, condataset
1616
from .datastore import Datastore
1717
from .groups import (
1818
ExpectationValueDataGroup,
@@ -32,4 +32,5 @@
3232
"MeasurementOutcomesDataGroup",
3333
"OQDTestbenchDataGroup",
3434
"SinaraRawDataGroup",
35+
"condataset",
3536
]

0 commit comments

Comments
 (0)