Skip to content

Commit

Permalink
Add initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Apr 2, 2024
1 parent 5aae971 commit 7d8b6ff
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions properties/test_index_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from hypothesis import note, settings
from hypothesis.stateful import (
RuleBasedStateMachine,
initialize,
invariant,
precondition,
rule,
Expand Down Expand Up @@ -50,6 +51,14 @@ def unique(draw, strategy):
)


def add_dim_coord_and_data_var(ds, var):
(name,) = var.dims
# dim coord
ds[name] = var
# non-dim coord of same size; this allows renaming
ds[name + "_"] = var


class DatasetStateMachine(RuleBasedStateMachine):
# Can't use bundles because we'd need pre-conditions on consumes(bundle)
# indexed_dims = Bundle("indexed_dims")
Expand All @@ -65,15 +74,20 @@ def __init__(self):
self.indexed_dims = []
self.multi_indexed_dims = []

@initialize(var=index_variables)
def init_ds(self, var):
"""Initialize the Dataset so that at least one rule will always fire."""
(name,) = var.dims
add_dim_coord_and_data_var(self.dataset, var)

self.indexed_dims.append(name)

# TODO: stacking with a timedelta64 index and unstacking converts it to object
@rule(var=index_variables)
def add_dim_coord(self, var):
(name,) = var.dims
note(f"adding dimension coordinate {name}")
# dim coord
self.dataset[name] = var
# non-dim coord of same size; this allows renaming
self.dataset[name + "_"] = var
add_dim_coord_and_data_var(self.dataset, var)

self.indexed_dims.append(name)

Expand Down

0 comments on commit 7d8b6ff

Please sign in to comment.