Skip to content

Commit e594a66

Browse files
authored
Merge pull request #2844 from benjeffery/fix-jsonschema-2
Fix jsonschema validators error
2 parents f80e085 + 8b03221 commit e594a66

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

python/tests/test_combinatorics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# MIT License
33
#
4-
# Copyright (c) 2020-2022 Tskit Developers
4+
# Copyright (c) 2020-2023 Tskit Developers
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@
2727
import io
2828
import itertools
2929
import json
30+
import math
3031
import random
3132

3233
import msprime
@@ -1057,7 +1058,7 @@ def num_leaf_labelled_binary_trees(n):
10571058
10581059
https://oeis.org/A005373/
10591060
"""
1060-
return int(np.math.factorial(2 * n - 3) / (2 ** (n - 2) * np.math.factorial(n - 2)))
1061+
return int(math.factorial(2 * n - 3) / (2 ** (n - 2) * math.factorial(n - 2)))
10611062

10621063

10631064
class TestPolytomySplitting:

python/tests/test_tables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,13 +1603,13 @@ def test_bad_indexes(self, table):
16031603
table[[5.5]]
16041604
with pytest.raises(TypeError, match="Cannot convert"):
16051605
table[[None]]
1606-
with pytest.raises(TypeError, match="not supported between instances"):
1606+
with pytest.raises(TypeError, match="not supported|did not contain"):
16071607
table[["foobar"]]
16081608
with pytest.raises(TypeError, match="Index must be integer, slice or iterable"):
16091609
table[5.5]
16101610
with pytest.raises(TypeError, match="Cannot convert to a rectangular array"):
16111611
table[None]
1612-
with pytest.raises(TypeError, match="not supported between instances"):
1612+
with pytest.raises(TypeError, match="not supported|did not contain"):
16131613
table["foobar"]
16141614

16151615

python/tskit/metadata.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22
#
3-
# Copyright (c) 2020-2022 Tskit Developers
3+
# Copyright (c) 2020-2023 Tskit Developers
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -193,7 +193,11 @@ def binary_format_validator(validator, types, instance, schema):
193193
# generators of exceptions, hence the yielding
194194

195195
# Make sure the normal type validation gets done
196-
yield from jsonschema._validators.type(validator, types, instance, schema)
196+
try:
197+
yield from jsonschema._validators.type(validator, types, instance, schema)
198+
except AttributeError:
199+
# Needed since jsonschema==4.19.1
200+
yield from jsonschema._keywords.type(validator, types, instance, schema)
197201

198202
# Non-composite types must have a binaryFormat
199203
if validator.is_type(instance, "object"):
@@ -222,7 +226,13 @@ def binary_format_validator(validator, types, instance, schema):
222226

223227
def required_validator(validator, required, instance, schema):
224228
# Do the normal validation
225-
yield from jsonschema._validators.required(validator, required, instance, schema)
229+
try:
230+
yield from jsonschema._validators.required(
231+
validator, required, instance, schema
232+
)
233+
except AttributeError:
234+
# Needed since jsonschema==4.19.1
235+
yield from jsonschema._keywords.required(validator, required, instance, schema)
226236

227237
# For struct codec if a property is not required, then it must have a default
228238
for prop, sub_schema in instance["properties"].items():

0 commit comments

Comments
 (0)