@@ -1916,8 +1916,9 @@ def test_array_read_only(self, name, ts_fixture):
19161916 a [:] = 0
19171917 with pytest .raises (ValueError , match = "assignment destination" ):
19181918 a [0 ] = 0
1919- with pytest .raises (ValueError , match = "cannot set WRITEABLE" ):
1920- a .setflags (write = True )
1919+ if name != "sites_ancestral_state" :
1920+ with pytest .raises (ValueError , match = "cannot set WRITEABLE" ):
1921+ a .setflags (write = True )
19211922
19221923 @pytest .mark .parametrize ("name" , ARRAY_NAMES )
19231924 def test_array_properties (self , name , ts_fixture ):
@@ -1927,13 +1928,17 @@ def test_array_properties(self, name, ts_fixture):
19271928 assert not a .flags .writeable
19281929 assert a .flags .aligned
19291930 assert a .flags .c_contiguous
1930- assert not a .flags .owndata
1931+ if name == "sites_ancestral_state" :
1932+ assert a .flags .owndata
1933+ else :
1934+ assert not a .flags .owndata
19311935 b = getattr (ts_fixture , name )
19321936 assert a is not b
19331937 assert np .all (a == b )
19341938 # This checks that the underlying pointer to memory is the same in
19351939 # both arrays.
1936- assert a .__array_interface__ == b .__array_interface__
1940+ if name != "sites_ancestral_state" :
1941+ assert a .__array_interface__ == b .__array_interface__
19371942
19381943 @pytest .mark .parametrize ("name" , ARRAY_NAMES )
19391944 def test_array_lifetime (self , name , ts_fixture ):
@@ -1976,7 +1981,8 @@ def test_individuals_nodes(self, ts_fixture):
19761981 assert a3 is not a2
19771982
19781983 @pytest .mark .parametrize (
1979- "site_lengths" , ["none" , "all-0" , "all-1" , "all-2" , "mixed" , "very_long" ]
1984+ "site_lengths" ,
1985+ ["none" , "all-0" , "all-1" , "all-2" , "mixed" , "very_long" , "unicode" ],
19801986 )
19811987 def test_sites_ancestral_state (self , ts_fixture , site_lengths ):
19821988 if site_lengths == "none" :
@@ -1995,6 +2001,7 @@ def test_sites_ancestral_state(self, ts_fixture, site_lengths):
19952001 "all-2" : lambda i , site : "YO" ,
19962002 "mixed" : lambda i , site : "A" * i ,
19972003 "very_long" : lambda i , site : "A" * 100_000_000 if i == 0 else "A" ,
2004+ "unicode" : lambda i , site : "💩" * (i + 1 ),
19982005 }
19992006
20002007 get_ancestral_state = ancestral_state_map [site_lengths ]
@@ -2003,15 +2010,22 @@ def test_sites_ancestral_state(self, ts_fixture, site_lengths):
20032010 site .replace (ancestral_state = get_ancestral_state (i , site ))
20042011 )
20052012 ts = tables .tree_sequence ()
2006- ts = ts .ll_tree_sequence
2013+ ll_ts = ts .ll_tree_sequence
2014+
2015+ a = ll_ts .sites_ancestral_state
2016+ # Contents
2017+ if site_lengths == "none" :
2018+ assert a .size == 0
2019+ else :
2020+ for site in ts .sites ():
2021+ assert a [site .id ] == site .ancestral_state
20072022
20082023 # Read only
20092024 with pytest .raises (AttributeError , match = "not writable" ):
2010- ts .sites_ancestral_state = None
2025+ ll_ts .sites_ancestral_state = None
20112026 with pytest .raises (AttributeError , match = "not writable" ):
2012- del ts .sites_ancestral_state
2027+ del ll_ts .sites_ancestral_state
20132028
2014- a = ts .sites_ancestral_state
20152029 with pytest .raises (ValueError , match = "assignment destination" ):
20162030 a [:] = 0
20172031 with pytest .raises (ValueError , match = "assignment destination" ):
@@ -2021,18 +2035,17 @@ def test_sites_ancestral_state(self, ts_fixture, site_lengths):
20212035 a .setflags (write = True )
20222036
20232037 # Properties
2024- a = ts .sites_ancestral_state
20252038 assert a .flags .aligned
20262039 assert a .flags .c_contiguous
2027- b = ts .sites_ancestral_state
2040+ b = ll_ts .sites_ancestral_state
20282041 assert a is not b
20292042 assert np .all (a == b )
20302043
20312044 # Lifetime
2032- a1 = ts .sites_ancestral_state
2045+ a1 = ll_ts .sites_ancestral_state
20332046 a2 = a1 .copy ()
20342047 assert a1 is not a2
2035- del ts
2048+ del ll_ts
20362049 # Do some memory operations
20372050 a3 = np .ones (10 ** 6 )
20382051 assert np .all (a1 == a2 )
0 commit comments