diff --git a/python/tests/test_highlevel.py b/python/tests/test_highlevel.py index 12c558dac4..a03608756c 100644 --- a/python/tests/test_highlevel.py +++ b/python/tests/test_highlevel.py @@ -1238,7 +1238,7 @@ def test_samples_time_interval(self, time_interval): def test_samples_example(self): tables = tskit.TableCollection(sequence_length=10) - time = [np.array(0), 0, np.array([1]), 1, 1, 3, 3.00001, 3.0 - 0.0001, 1 / 3] + time = [0, 0, 1, 1, 1, 3, 3.00001, 3.0 - 0.0001, 1 / 3] pops = [1, 3, 1, 2, 1, 1, 1, 3, 1] for _ in range(max(pops) + 1): tables.populations.add_row() diff --git a/python/tests/test_tables.py b/python/tests/test_tables.py index 19055dc0fb..30ef6634fe 100644 --- a/python/tests/test_tables.py +++ b/python/tests/test_tables.py @@ -813,7 +813,11 @@ def test_bad_offsets(self): for _list_col, offset_col in self.ragged_list_columns: original_offset = np.copy(input_data[offset_col.name]) - input_data[offset_col.name][0] = -1 + # As numpy no longer allows conversion of out-of-bounds values, we + # explictly cast first. + input_data[offset_col.name][0] = np.array(-1).astype( + input_data[offset_col.name].dtype + ) with pytest.raises(ValueError): t.set_columns(**input_data) input_data[offset_col.name] = np.copy(original_offset) @@ -828,7 +832,9 @@ def test_bad_offsets(self): t.set_columns(**input_data) input_data[offset_col.name] = np.copy(original_offset) - input_data[offset_col.name][0] = -1 + input_data[offset_col.name][0] = np.array(-1).astype( + input_data[offset_col.name].dtype + ) with pytest.raises(ValueError): t.append_columns(**input_data) input_data[offset_col.name] = np.copy(original_offset) diff --git a/python/tskit/formats.py b/python/tskit/formats.py index af36b20490..ac466ce1a8 100644 --- a/python/tskit/formats.py +++ b/python/tskit/formats.py @@ -1,6 +1,6 @@ # MIT License # -# Copyright (c) 2018-2021 Tskit Developers +# Copyright (c) 2018-2023 Tskit Developers # Copyright (c) 2016-2017 University of Oxford # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -471,6 +471,10 @@ def _dump_legacy_hdf5_v10(tree_sequence, root): def _load_legacy_hdf5_v10(root, remove_duplicate_positions=False): # We cannot have duplicate positions in v10, so this parameter is ignored sequence_length = root.attrs["sequence_length"] + try: + sequence_length = sequence_length[0] + except TypeError: + pass tables = tskit.TableCollection(sequence_length) nodes_group = root["nodes"] diff --git a/python/tskit/trees.py b/python/tskit/trees.py index 6fe40e635f..01c572dccf 100644 --- a/python/tskit/trees.py +++ b/python/tskit/trees.py @@ -8572,7 +8572,7 @@ def fst_func(sample_set_sizes, flattened, indexes, **kwargs): divergences.shape = (divergences.shape[0], 1, divergences.shape[1]) diversities.shape = (diversities.shape[0], 1, diversities.shape[1]) - fst = np.repeat(1.0, np.product(divergences.shape)) + fst = np.repeat(1.0, np.prod(divergences.shape)) fst.shape = divergences.shape for i, (u, v) in enumerate(indexes): denom = ( @@ -9167,7 +9167,7 @@ def pairwise_diversity(self, samples=None): return float( self.diversity( [samples], windows=[0, self.sequence_length], span_normalise=False - )[0] + )[0][0] ) def get_time(self, u):