Skip to content

Commit 8de719f

Browse files
benjefferymergify[bot]
authored andcommitted
Fix numpy warnings
1 parent 53ca1d2 commit 8de719f

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

python/tests/test_highlevel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ def test_samples_time_interval(self, time_interval):
12381238

12391239
def test_samples_example(self):
12401240
tables = tskit.TableCollection(sequence_length=10)
1241-
time = [np.array(0), 0, np.array([1]), 1, 1, 3, 3.00001, 3.0 - 0.0001, 1 / 3]
1241+
time = [0, 0, 1, 1, 1, 3, 3.00001, 3.0 - 0.0001, 1 / 3]
12421242
pops = [1, 3, 1, 2, 1, 1, 1, 3, 1]
12431243
for _ in range(max(pops) + 1):
12441244
tables.populations.add_row()

python/tests/test_tables.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,11 @@ def test_bad_offsets(self):
813813

814814
for _list_col, offset_col in self.ragged_list_columns:
815815
original_offset = np.copy(input_data[offset_col.name])
816-
input_data[offset_col.name][0] = -1
816+
# As numpy no longer allows conversion of out-of-bounds values, we
817+
# explictly cast first.
818+
input_data[offset_col.name][0] = np.array(-1).astype(
819+
input_data[offset_col.name].dtype
820+
)
817821
with pytest.raises(ValueError):
818822
t.set_columns(**input_data)
819823
input_data[offset_col.name] = np.copy(original_offset)
@@ -828,7 +832,9 @@ def test_bad_offsets(self):
828832
t.set_columns(**input_data)
829833
input_data[offset_col.name] = np.copy(original_offset)
830834

831-
input_data[offset_col.name][0] = -1
835+
input_data[offset_col.name][0] = np.array(-1).astype(
836+
input_data[offset_col.name].dtype
837+
)
832838
with pytest.raises(ValueError):
833839
t.append_columns(**input_data)
834840
input_data[offset_col.name] = np.copy(original_offset)

python/tskit/formats.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22
#
3-
# Copyright (c) 2018-2021 Tskit Developers
3+
# Copyright (c) 2018-2023 Tskit Developers
44
# Copyright (c) 2016-2017 University of Oxford
55
#
66
# 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):
471471
def _load_legacy_hdf5_v10(root, remove_duplicate_positions=False):
472472
# We cannot have duplicate positions in v10, so this parameter is ignored
473473
sequence_length = root.attrs["sequence_length"]
474+
try:
475+
sequence_length = sequence_length[0]
476+
except TypeError:
477+
pass
474478
tables = tskit.TableCollection(sequence_length)
475479

476480
nodes_group = root["nodes"]

python/tskit/trees.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8572,7 +8572,7 @@ def fst_func(sample_set_sizes, flattened, indexes, **kwargs):
85728572
divergences.shape = (divergences.shape[0], 1, divergences.shape[1])
85738573
diversities.shape = (diversities.shape[0], 1, diversities.shape[1])
85748574

8575-
fst = np.repeat(1.0, np.product(divergences.shape))
8575+
fst = np.repeat(1.0, np.prod(divergences.shape))
85768576
fst.shape = divergences.shape
85778577
for i, (u, v) in enumerate(indexes):
85788578
denom = (
@@ -9167,7 +9167,7 @@ def pairwise_diversity(self, samples=None):
91679167
return float(
91689168
self.diversity(
91699169
[samples], windows=[0, self.sequence_length], span_normalise=False
9170-
)[0]
9170+
)[0][0]
91719171
)
91729172

91739173
def get_time(self, u):

0 commit comments

Comments
 (0)