Skip to content

Commit

Permalink
Fix numpy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
benjeffery authored and mergify[bot] committed Oct 5, 2023
1 parent 53ca1d2 commit 8de719f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/tests/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions python/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion python/tskit/formats.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 8de719f

Please sign in to comment.