@@ -5546,9 +5546,34 @@ def test_equality_mutations_derived_state(self, ts):
5546
5546
[mutation .derived_state for mutation in ts .mutations ()],
5547
5547
)
5548
5548
5549
+ @pytest .mark .skipif (not _tskit .HAS_NUMPY_2 , reason = "Requires NumPy 2.0 or higher" )
5550
+ @pytest .mark .parametrize ("ts" , tsutil .get_example_tree_sequences ())
5551
+ def test_mutations_inherited_state (self , ts ):
5552
+ inherited_state = ts .mutations_inherited_state
5553
+ assert len (inherited_state ) == ts .num_mutations
5554
+ assert isinstance (inherited_state , np .ndarray )
5555
+ assert inherited_state .shape == (ts .num_mutations ,)
5556
+ assert inherited_state .dtype == np .dtype ("T" )
5557
+ assert inherited_state .size == ts .num_mutations
5558
+
5559
+ for mut in ts .mutations ():
5560
+ state0 = ts .site (mut .site ).ancestral_state
5561
+ if mut .parent != - 1 :
5562
+ state0 = ts .mutation (mut .parent ).derived_state
5563
+ assert state0 == inherited_state [mut .id ]
5564
+
5565
+ # Test caching - second access should return the same object
5566
+ inherited_state2 = ts .mutations_inherited_state
5567
+ assert inherited_state is inherited_state2
5568
+
5549
5569
@pytest .mark .skipif (_tskit .HAS_NUMPY_2 , reason = "Test only on Numpy 1.X" )
5550
5570
@pytest .mark .parametrize (
5551
- "column" , ["sites_ancestral_state" , "mutations_derived_state" ]
5571
+ "column" ,
5572
+ [
5573
+ "sites_ancestral_state" ,
5574
+ "mutations_derived_state" ,
5575
+ "mutations_inherited_state" ,
5576
+ ],
5552
5577
)
5553
5578
def test_ragged_array_not_supported (self , column ):
5554
5579
tables = tskit .TableCollection (sequence_length = 100 )
0 commit comments