From 388d0aba00a60cc8120154bbc43cc4b5ff063727 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:23:24 +0100 Subject: [PATCH 01/21] fix: convert an integer beyond the double range to infinity in to_rdf Signed-off-by: jdsika --- lib/pyld/jsonld.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index f8ffb1f72..de80ae5c4 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -4016,7 +4016,7 @@ def _object_to_rdf(self, item, issuer, triples, options): elif datatype == str(XSD.double): # since the previous branch did not activate, we know that `value` is not a float number. try: - float_value = float(value) + float_value = _to_double(value) except (ValueError, TypeError): # if `value` is not convertible to float, we will return it as-is. return Literal(value, datatype=XSD.double, normalize=False) @@ -6460,9 +6460,26 @@ def _is_double(v): return not isinstance(v, Integral) and isinstance(v, Real) and not float(v).is_integer() +def _to_double(value) -> float: + """ + Converts a number to a double. + + An integer beyond the range of a double becomes infinite, as it does when + JavaScript parses JSON. + + :param value: the number to convert. + + :return: the double. + """ + try: + return float(value) + except OverflowError: + return math.inf if value > 0 else -math.inf + + def _canonicalize_double(value: float) -> str: """Convert a float value to canonical lexical form of `xsd:double`.""" - return re.sub(r'(\d)0*E\+?(-)?0*(\d)', r'\1E\2\3', (f'{value:1.15E}')) + return re.sub(r'(\d)0*E\+?(-)?0*(\d)', r'\1E\2\3', (f'{_to_double(value):1.15E}')) def _is_numeric(v): @@ -6474,7 +6491,7 @@ def _is_numeric(v): :return: True if the value is numeric, False if not. """ try: - float(v) + _to_double(v) return True except (TypeError, ValueError): return False From ee5d0356cf2d6c322f17daeba352dcb57cf0fd3b Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:23:24 +0100 Subject: [PATCH 02/21] test: convert integers beyond the double range to infinity in to_rdf Signed-off-by: jdsika --- tests/jsonld/test_to_rdf.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/jsonld/test_to_rdf.py b/tests/jsonld/test_to_rdf.py index 4e080fea3..ab7996adb 100644 --- a/tests/jsonld/test_to_rdf.py +++ b/tests/jsonld/test_to_rdf.py @@ -124,6 +124,36 @@ def test_large_integer_to_rdf_double_conversion_processing_mode(): """ assert nquads == expected +def test_integer_beyond_double_range_to_rdf_is_infinite(): + """ + An integer too large for a double is an infinite xsd:double, as JavaScript + reads it, instead of raising OverflowError. + """ + for value, lexical in ((10**309, 'INF'), (-(10**309), '-INF')): + input = {'@id': 'http://example.com/s', 'http://example.com/p': value} + + nquads = jsonld.to_rdf(input, options={'format': 'application/n-quads'}) + + assert nquads == ( + f' "{lexical}"' + '^^ .\n\n' + ) + + +def test_integer_beyond_double_range_typed_as_double_to_rdf_is_infinite(): + input = { + '@id': 'http://example.com/s', + 'http://example.com/p': { + '@value': 10**309, + '@type': 'http://www.w3.org/2001/XMLSchema#double', + }, + } + + nquads = jsonld.to_rdf(input, options={'format': 'application/n-quads'}) + + assert '"INF"^^' in nquads + + def test_to_rdf_uses_identifier_issuer_option(): input = {'http://example.org/p': [{'@list': ['a', 'b']}]} issuer = IdentifierIssuer('_:custom') From d3050dda2464c4cbd7ad84d223251b8ada36f682 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:24:05 +0100 Subject: [PATCH 03/21] docs: add the large integer fix to the changelog Signed-off-by: jdsika --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50bf684c4..f895fbf94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - IRI validation now detects multiple # fragments so these IRI's are skipped during toRDF. Fixes [toRdf#te111](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te111) and [toRdf#te112](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te112). - In `_create_node_map()`, ignored `@id: None` subjects are now dropped before they enter the node map to prevent `_graph_to_rdf()` from crashing when sorting mixed `None` and string keys. Fixes [toRdf#te122](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122). - Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075). +- `jsonld.to_rdf()` converts an integer too large for a double to an infinite `xsd:double` (`INF`), as a JavaScript processor reads it, instead of raising `OverflowError`. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 58824814c6b754cf497c01bdfe059e783d20183e Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:32:59 +0100 Subject: [PATCH 04/21] refactor: type _canonicalize_double for integers as well Signed-off-by: jdsika --- lib/pyld/jsonld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index de80ae5c4..42b57b6f0 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -6477,7 +6477,7 @@ def _to_double(value) -> float: return math.inf if value > 0 else -math.inf -def _canonicalize_double(value: float) -> str: +def _canonicalize_double(value: float | int) -> str: """Convert a float value to canonical lexical form of `xsd:double`.""" return re.sub(r'(\d)0*E\+?(-)?0*(\d)', r'\1E\2\3', (f'{_to_double(value):1.15E}')) From 675a798f00b8683a36de8e7c66e507ff801eb251 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:33:00 +0100 Subject: [PATCH 05/21] test: check large integers exactly and in json-ld-1.0 mode in to_rdf Signed-off-by: jdsika --- tests/jsonld/test_to_rdf.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/jsonld/test_to_rdf.py b/tests/jsonld/test_to_rdf.py index ab7996adb..c4f6e9aaa 100644 --- a/tests/jsonld/test_to_rdf.py +++ b/tests/jsonld/test_to_rdf.py @@ -124,6 +124,7 @@ def test_large_integer_to_rdf_double_conversion_processing_mode(): """ assert nquads == expected + def test_integer_beyond_double_range_to_rdf_is_infinite(): """ An integer too large for a double is an infinite xsd:double, as JavaScript @@ -141,6 +142,9 @@ def test_integer_beyond_double_range_to_rdf_is_infinite(): def test_integer_beyond_double_range_typed_as_double_to_rdf_is_infinite(): + """ + An integer too large for a double, typed as xsd:double, is infinite too. + """ input = { '@id': 'http://example.com/s', 'http://example.com/p': { @@ -151,7 +155,27 @@ def test_integer_beyond_double_range_typed_as_double_to_rdf_is_infinite(): nquads = jsonld.to_rdf(input, options={'format': 'application/n-quads'}) - assert '"INF"^^' in nquads + assert nquads == ( + ' "INF"' + '^^ .\n\n' + ) + + +def test_integer_beyond_double_range_in_json_ld_1_0_stays_an_integer(): + """ + In json-ld-1.0 processing mode, such an integer is kept as xsd:integer. + """ + input = {'@id': 'http://example.com/s', 'http://example.com/p': 10**309} + + nquads = jsonld.to_rdf( + input, + options={'format': 'application/n-quads', 'processingMode': 'json-ld-1.0'}, + ) + + assert nquads == ( + f' "{10**309}"' + '^^ .\n\n' + ) def test_to_rdf_uses_identifier_issuer_option(): From fb52591e577fd096504e455c47ab1bba5e94bfca Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:33:00 +0100 Subject: [PATCH 06/21] test: expand an integer beyond the double range Signed-off-by: jdsika --- tests/jsonld/test_expand.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/jsonld/test_expand.py b/tests/jsonld/test_expand.py index 6e63ceebc..f51b0ef4e 100644 --- a/tests/jsonld/test_expand.py +++ b/tests/jsonld/test_expand.py @@ -692,3 +692,20 @@ def test_default_direction_null_reset_is_noop_when_unset(): ] assert jsonld.expand(input) == expected + + +def test_integer_beyond_double_range_is_kept(): + """ + An integer too large for a double is a number like any other, instead of + raising OverflowError. + """ + input = {"@id": "http://example.com/s", "http://example.com/p": 10**309} + + expected = [ + { + "@id": "http://example.com/s", + "http://example.com/p": [{"@value": 10**309}], + }, + ] + + assert jsonld.expand(input) == expected From da6b52985741725f99ec037569d3aaeb48a5275f Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 14:33:01 +0100 Subject: [PATCH 07/21] docs: describe the large integer fix more precisely in the changelog Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f895fbf94..d47b82179 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ - IRI validation now detects multiple # fragments so these IRI's are skipped during toRDF. Fixes [toRdf#te111](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te111) and [toRdf#te112](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te112). - In `_create_node_map()`, ignored `@id: None` subjects are now dropped before they enter the node map to prevent `_graph_to_rdf()` from crashing when sorting mixed `None` and string keys. Fixes [toRdf#te122](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122). - Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075). -- `jsonld.to_rdf()` converts an integer too large for a double to an infinite `xsd:double` (`INF`), as a JavaScript processor reads it, instead of raising `OverflowError`. +- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as the infinite `xsd:double` `INF` (in `json-ld-1.0` mode, still as an exact `xsd:integer`). `@json` literals still reject such numbers, as RFC 8785 does. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 0aafefa91d02d6a3b7a3898038462e2575d3359e Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:29:27 +0100 Subject: [PATCH 08/21] fix: write the xsd:double NaN as NaN, its XSD canonical form Signed-off-by: jdsika --- lib/pyld/jsonld.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index 42b57b6f0..ec8810034 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -6479,7 +6479,11 @@ def _to_double(value) -> float: def _canonicalize_double(value: float | int) -> str: """Convert a float value to canonical lexical form of `xsd:double`.""" - return re.sub(r'(\d)0*E\+?(-)?0*(\d)', r'\1E\2\3', (f'{_to_double(value):1.15E}')) + value = _to_double(value) + if math.isnan(value): + # Python formats NaN as 'NAN'; the XSD canonical form is 'NaN'. + return 'NaN' + return re.sub(r'(\d)0*E\+?(-)?0*(\d)', r'\1E\2\3', (f'{value:1.15E}')) def _is_numeric(v): From 6bbd3f336a72603ad6e88a7018307345dfd68203 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:29:27 +0100 Subject: [PATCH 09/21] test: write special xsd:double values in their XSD canonical forms Signed-off-by: jdsika --- tests/jsonld/test_to_rdf.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/jsonld/test_to_rdf.py b/tests/jsonld/test_to_rdf.py index c4f6e9aaa..9cfaaafc8 100644 --- a/tests/jsonld/test_to_rdf.py +++ b/tests/jsonld/test_to_rdf.py @@ -178,6 +178,30 @@ def test_integer_beyond_double_range_in_json_ld_1_0_stays_an_integer(): ) +def test_double_special_values_to_rdf_use_xsd_canonical_forms(): + """ + The special xsd:double values are written as INF, -INF and NaN, the XSD + canonical forms, whether they come as numbers or as typed strings. + """ + double = 'http://www.w3.org/2001/XMLSchema#double' + for value, lexical in ( + (float('nan'), 'NaN'), + (float('inf'), 'INF'), + (float('-inf'), '-INF'), + ({'@value': 'NaN', '@type': double}, 'NaN'), + ({'@value': 'INF', '@type': double}, 'INF'), + ({'@value': '-INF', '@type': double}, '-INF'), + ): + input = {'@id': 'http://example.com/s', 'http://example.com/p': value} + + nquads = jsonld.to_rdf(input, options={'format': 'application/n-quads'}) + + assert nquads == ( + f' "{lexical}"' + f'^^<{double}> .\n\n' + ) + + def test_to_rdf_uses_identifier_issuer_option(): input = {'http://example.org/p': [{'@list': ['a', 'b']}]} issuer = IdentifierIssuer('_:custom') From f932bbe4907b11164a475b404a602ca014d0bcf8 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:29:28 +0100 Subject: [PATCH 10/21] docs: add the NaN canonical form fix to the changelog Signed-off-by: jdsika --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d47b82179..5227f72e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ - In `_create_node_map()`, ignored `@id: None` subjects are now dropped before they enter the node map to prevent `_graph_to_rdf()` from crashing when sorting mixed `None` and string keys. Fixes [toRdf#te122](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122). - Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075). - `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as the infinite `xsd:double` `INF` (in `json-ld-1.0` mode, still as an exact `xsd:integer`). `@json` literals still reject such numbers, as RFC 8785 does. +- `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 35fe25ced82df9fe2a6e749f4b501145f70fa301 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:39:59 +0100 Subject: [PATCH 11/21] refactor: map the special xsd:double values explicitly in _canonicalize_double Signed-off-by: jdsika --- lib/pyld/jsonld.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index ec8810034..aee1e1916 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -6464,8 +6464,9 @@ def _to_double(value) -> float: """ Converts a number to a double. - An integer beyond the range of a double becomes infinite, as it does when - JavaScript parses JSON. + An integer beyond the range of a double becomes infinite, as the XSD + lexical mapping of `xsd:double` rounds it (XML Schema 1.1 Part 2, + floatingPointRound), and as JavaScript reads it from JSON. :param value: the number to convert. @@ -6478,11 +6479,21 @@ def _to_double(value) -> float: def _canonicalize_double(value: float | int) -> str: - """Convert a float value to canonical lexical form of `xsd:double`.""" + """ + Converts a number to the canonical lexical form of `xsd:double`. + + The special values are written 'INF', '-INF' and 'NaN' (XML Schema 1.1 + Part 2, specialRepCanonicalMap). + + :param value: the number to convert. + + :return: the canonical lexical form. + """ value = _to_double(value) if math.isnan(value): - # Python formats NaN as 'NAN'; the XSD canonical form is 'NaN'. return 'NaN' + if math.isinf(value): + return 'INF' if value > 0 else '-INF' return re.sub(r'(\d)0*E\+?(-)?0*(\d)', r'\1E\2\3', (f'{value:1.15E}')) From 6b2538845b1b082fbb9cce756a05059d59c1b3c2 Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:39:59 +0100 Subject: [PATCH 12/21] test: describe the typed strings in the special double test accurately Signed-off-by: jdsika --- tests/jsonld/test_to_rdf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/jsonld/test_to_rdf.py b/tests/jsonld/test_to_rdf.py index 9cfaaafc8..3a03a4dd6 100644 --- a/tests/jsonld/test_to_rdf.py +++ b/tests/jsonld/test_to_rdf.py @@ -181,7 +181,8 @@ def test_integer_beyond_double_range_in_json_ld_1_0_stays_an_integer(): def test_double_special_values_to_rdf_use_xsd_canonical_forms(): """ The special xsd:double values are written as INF, -INF and NaN, the XSD - canonical forms, whether they come as numbers or as typed strings. + canonical forms. The typed strings are already canonical; PyLD rewrites + typed xsd:double strings, so they must stay so. """ double = 'http://www.w3.org/2001/XMLSchema#double' for value, lexical in ( From 19ae3886611af1a272cc273f5829278a8f3578ca Mon Sep 17 00:00:00 2001 From: jdsika Date: Wed, 4 Nov 2026 15:40:00 +0100 Subject: [PATCH 13/21] docs: correct the large integer and NaN changelog entries Signed-off-by: jdsika --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5227f72e2..96c045e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,8 +31,8 @@ - IRI validation now detects multiple # fragments so these IRI's are skipped during toRDF. Fixes [toRdf#te111](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te111) and [toRdf#te112](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te112). - In `_create_node_map()`, ignored `@id: None` subjects are now dropped before they enter the node map to prevent `_graph_to_rdf()` from crashing when sorting mixed `None` and string keys. Fixes [toRdf#te122](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122). - Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075). -- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as the infinite `xsd:double` `INF` (in `json-ld-1.0` mode, still as an exact `xsd:integer`). `@json` literals still reject such numbers, as RFC 8785 does. -- `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`. +- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as `INF`, the infinite `xsd:double` (in `json-ld-1.0` mode, as an exact `xsd:integer`). `@json` literals still reject such numbers, as RFC 8785 does. +- `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`. This changes `jsonld.normalize()` output, and so RDFC-1.0 hashes, of documents with such a value. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From f7ce712bdddb11cb2aaa0a77ad8602eb525755d0 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 13:45:39 +0100 Subject: [PATCH 14/21] docs: link the specs in the xsd:double helper docstrings Signed-off-by: jdsika --- lib/pyld/jsonld.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index aee1e1916..691180446 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -6464,9 +6464,9 @@ def _to_double(value) -> float: """ Converts a number to a double. - An integer beyond the range of a double becomes infinite, as the XSD - lexical mapping of `xsd:double` rounds it (XML Schema 1.1 Part 2, - floatingPointRound), and as JavaScript reads it from JSON. + An integer beyond the range of a double becomes positive or negative + infinity, as floatingPointRound in XML Schema 1.1 Part 2 rounds it: + https://www.w3.org/TR/xmlschema11-2/#f-floatPtRound :param value: the number to convert. @@ -6482,8 +6482,12 @@ def _canonicalize_double(value: float | int) -> str: """ Converts a number to the canonical lexical form of `xsd:double`. - The special values are written 'INF', '-INF' and 'NaN' (XML Schema 1.1 - Part 2, specialRepCanonicalMap). + A finite number is written as JSON-LD 1.1 describes it: + https://www.w3.org/TR/json-ld11-api/#data-round-tripping + + The special values are written 'INF', '-INF' and 'NaN', as + specialRepCanonicalMap in XML Schema 1.1 Part 2 maps them: + https://www.w3.org/TR/xmlschema11-2/#f-specValCanMap :param value: the number to convert. From a3675ce4f2a35aea1e228882b072b1552bb410e8 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 13:45:39 +0100 Subject: [PATCH 15/21] test: describe the expected behaviour in the large integer and special double to_rdf tests Signed-off-by: jdsika --- tests/jsonld/test_to_rdf.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/jsonld/test_to_rdf.py b/tests/jsonld/test_to_rdf.py index 3a03a4dd6..860752778 100644 --- a/tests/jsonld/test_to_rdf.py +++ b/tests/jsonld/test_to_rdf.py @@ -127,8 +127,8 @@ def test_large_integer_to_rdf_double_conversion_processing_mode(): def test_integer_beyond_double_range_to_rdf_is_infinite(): """ - An integer too large for a double is an infinite xsd:double, as JavaScript - reads it, instead of raising OverflowError. + Integers too large for a double should be converted to INF and -INF + xsd:double values instead of raising OverflowError. """ for value, lexical in ((10**309, 'INF'), (-(10**309), '-INF')): input = {'@id': 'http://example.com/s', 'http://example.com/p': value} @@ -143,7 +143,7 @@ def test_integer_beyond_double_range_to_rdf_is_infinite(): def test_integer_beyond_double_range_typed_as_double_to_rdf_is_infinite(): """ - An integer too large for a double, typed as xsd:double, is infinite too. + Integers too large for a double, typed as xsd:double, should be marked as infinite. """ input = { '@id': 'http://example.com/s', @@ -163,7 +163,8 @@ def test_integer_beyond_double_range_typed_as_double_to_rdf_is_infinite(): def test_integer_beyond_double_range_in_json_ld_1_0_stays_an_integer(): """ - In json-ld-1.0 processing mode, such an integer is kept as xsd:integer. + In json-ld-1.0 processing mode, integers too large for a double should be + kept as exact xsd:integer values. """ input = {'@id': 'http://example.com/s', 'http://example.com/p': 10**309} @@ -180,9 +181,8 @@ def test_integer_beyond_double_range_in_json_ld_1_0_stays_an_integer(): def test_double_special_values_to_rdf_use_xsd_canonical_forms(): """ - The special xsd:double values are written as INF, -INF and NaN, the XSD - canonical forms. The typed strings are already canonical; PyLD rewrites - typed xsd:double strings, so they must stay so. + The special xsd:double values should be written as NaN, INF and -INF, their + XSD canonical forms, whether given as floats or as xsd:double typed strings. """ double = 'http://www.w3.org/2001/XMLSchema#double' for value, lexical in ( From 53bb71860e0c57774e7dc0ad877b3dccd79e20dd Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 13:45:40 +0100 Subject: [PATCH 16/21] test: describe the expected behaviour in the large integer expand test Signed-off-by: jdsika --- tests/jsonld/test_expand.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/jsonld/test_expand.py b/tests/jsonld/test_expand.py index f51b0ef4e..05af4999c 100644 --- a/tests/jsonld/test_expand.py +++ b/tests/jsonld/test_expand.py @@ -696,8 +696,8 @@ def test_default_direction_null_reset_is_noop_when_unset(): def test_integer_beyond_double_range_is_kept(): """ - An integer too large for a double is a number like any other, instead of - raising OverflowError. + Integers too large for a double should be kept as numbers during expansion + instead of raising OverflowError. """ input = {"@id": "http://example.com/s", "http://example.com/p": 10**309} From 8995b4c655f768b31ca7df164922e91dc10a2c20 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 13:45:40 +0100 Subject: [PATCH 17/21] docs: drop the RDFC-1.0 mention from the NaN changelog entry Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96c045e72..a65785a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ - In `_create_node_map()`, ignored `@id: None` subjects are now dropped before they enter the node map to prevent `_graph_to_rdf()` from crashing when sorting mixed `None` and string keys. Fixes [toRdf#te122](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122). - Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075). - `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as `INF`, the infinite `xsd:double` (in `json-ld-1.0` mode, as an exact `xsd:integer`). `@json` literals still reject such numbers, as RFC 8785 does. -- `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`. This changes `jsonld.normalize()` output, and so RDFC-1.0 hashes, of documents with such a value. +- `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`, so `jsonld.normalize()` output changes for documents with such a value. ### Changed - **BREAKING**: Developer install, command execution, documentation, and release artifact From 5f1efef87d365eb96760bf441765b71a3ccd4c44 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:01:05 +0100 Subject: [PATCH 18/21] refactor: canonicalize xsd:double typed strings with a single conversion Signed-off-by: jdsika --- lib/pyld/jsonld.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index 691180446..67557d692 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -4016,17 +4016,11 @@ def _object_to_rdf(self, item, issuer, triples, options): elif datatype == str(XSD.double): # since the previous branch did not activate, we know that `value` is not a float number. try: - float_value = _to_double(value) + lexical = _canonicalize_double(value) except (ValueError, TypeError): # if `value` is not convertible to float, we will return it as-is. - return Literal(value, datatype=XSD.double, normalize=False) - else: - # we have a float, and canonicalization may proceed. - return Literal( - _canonicalize_double(float_value), - datatype=XSD.double, - normalize=False, - ) + lexical = value + return Literal(lexical, datatype=XSD.double, normalize=False) elif ( options['processingMode'] == 'json-ld-1.1' and _is_integer(value) @@ -6478,7 +6472,7 @@ def _to_double(value) -> float: return math.inf if value > 0 else -math.inf -def _canonicalize_double(value: float | int) -> str: +def _canonicalize_double(value: float | int | str) -> str: """ Converts a number to the canonical lexical form of `xsd:double`. From d16f219711d27900ec32d8109af5b1a06fe4e0e2 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:01:06 +0100 Subject: [PATCH 19/21] docs: state the inputs and the overflow rounding of the xsd:double helpers Signed-off-by: jdsika --- lib/pyld/jsonld.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/pyld/jsonld.py b/lib/pyld/jsonld.py index 67557d692..cdc9159f8 100644 --- a/lib/pyld/jsonld.py +++ b/lib/pyld/jsonld.py @@ -6458,11 +6458,13 @@ def _to_double(value) -> float: """ Converts a number to a double. - An integer beyond the range of a double becomes positive or negative - infinity, as floatingPointRound in XML Schema 1.1 Part 2 rounds it: - https://www.w3.org/TR/xmlschema11-2/#f-floatPtRound + An integer that rounds beyond the largest double becomes positive or + negative infinity, as the lexical mapping of `xsd:double` in XML Schema + 1.1 Part 2 rounds it with floatingPointRound: + https://www.w3.org/TR/xmlschema11-2/#f-doubleLexmap - :param value: the number to convert. + :param value: the number or numeric string to convert; anything else + raises ValueError or TypeError, as float() does. :return: the double. """ @@ -6483,7 +6485,8 @@ def _canonicalize_double(value: float | int | str) -> str: specialRepCanonicalMap in XML Schema 1.1 Part 2 maps them: https://www.w3.org/TR/xmlschema11-2/#f-specValCanMap - :param value: the number to convert. + :param value: the number or numeric string to convert, as for + _to_double(). :return: the canonical lexical form. """ From c4cbabf1bd11463be39cc197e51a739c4ca7986f Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 14:01:07 +0100 Subject: [PATCH 20/21] docs: state where @json still overflows and -INF in the large integer changelog entry Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a65785a63..916289e95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ - IRI validation now detects multiple # fragments so these IRI's are skipped during toRDF. Fixes [toRdf#te111](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te111) and [toRdf#te112](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te112). - In `_create_node_map()`, ignored `@id: None` subjects are now dropped before they enter the node map to prevent `_graph_to_rdf()` from crashing when sorting mixed `None` and string keys. Fixes [toRdf#te122](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122). - Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075). -- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as `INF`, the infinite `xsd:double` (in `json-ld-1.0` mode, as an exact `xsd:integer`). `@json` literals still reject such numbers, as RFC 8785 does. +- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as `INF` or `-INF`, the infinite `xsd:double` values, or, in `json-ld-1.0` mode and not typed as `xsd:double`, as an exact `xsd:integer`. Inside `@json` literals, `jsonld.to_rdf()` and `jsonld.normalize()` still raise `OverflowError` for such numbers, as RFC 8785 only allows numbers that fit in a double. - `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`, so `jsonld.normalize()` output changes for documents with such a value. ### Changed From 57c19886680526627772564ca125430dacdab6c6 Mon Sep 17 00:00:00 2001 From: jdsika Date: Tue, 10 Nov 2026 16:10:12 +0100 Subject: [PATCH 21/21] docs: say the operations no longer fail with an OverflowError, which flatten wraps Signed-off-by: jdsika --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916289e95..71166a9b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ - IRI validation now detects multiple # fragments so these IRI's are skipped during toRDF. Fixes [toRdf#te111](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te111) and [toRdf#te112](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te112). - In `_create_node_map()`, ignored `@id: None` subjects are now dropped before they enter the node map to prevent `_graph_to_rdf()` from crashing when sorting mixed `None` and string keys. Fixes [toRdf#te122](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122). - Use a helper for generalized N-Quads normalization in the test runner, since rdflib cannot parse blank-node predicates. Fixes [toRdf#te075](https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te075). -- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer raise `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as `INF` or `-INF`, the infinite `xsd:double` values, or, in `json-ld-1.0` mode and not typed as `xsd:double`, as an exact `xsd:integer`. Inside `@json` literals, `jsonld.to_rdf()` and `jsonld.normalize()` still raise `OverflowError` for such numbers, as RFC 8785 only allows numbers that fit in a double. +- `jsonld.expand()`, `jsonld.to_rdf()` and the other operations no longer fail with an `OverflowError` for an integer too large for a double. `jsonld.to_rdf()` writes it as `INF` or `-INF`, the infinite `xsd:double` values, or, in `json-ld-1.0` mode and not typed as `xsd:double`, as an exact `xsd:integer`. Inside `@json` literals, `jsonld.to_rdf()` and `jsonld.normalize()` still raise `OverflowError` for such numbers, as RFC 8785 only allows numbers that fit in a double. - `jsonld.to_rdf()` writes the `xsd:double` NaN as `NaN`, its XSD canonical form, instead of `NAN`, so `jsonld.normalize()` output changes for documents with such a value. ### Changed