-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
fix to_json for numbers larger than sys.maxsize #34473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
95c20db
6d2f8bd
4fc5b87
abfca37
7e63941
3353420
c9574b8
94c112f
76576b8
9f211a5
2b7a271
5e06109
755ef47
0e768f8
12d73b0
6c2aa9f
1a8051f
552194e
e2898ef
2943995
771ec5d
92bc6ef
8f3af8c
cdae92e
1009168
759ad8a
5e01ed0
8a08a38
0441fe7
4630c0d
2e06a8b
63056fc
6ec960e
c63a5c9
b2f8f46
fea9348
6516078
aa2dbca
7eaf42d
56d5bac
1cdb1ba
821d51f
1001ac1
b8f16b6
a6e83c7
ccc5b47
585b985
7586698
0e6768f
7c19bd2
9809d7c
2739f3d
77d69b7
f003d6b
ee505c9
cdc0870
0fba3d5
259018d
a856a41
1bbfdc2
665b146
3608297
4ab13d6
176f212
9b58758
44b79f1
9cbf596
7ee21eb
948170c
ff2e25e
ce37048
2db12c0
3e820ac
7afeadb
e4df0f8
7b041fe
21d9e98
6fd15c9
c7acef1
2d43001
6053227
a688468
9e1b95f
cc0dd6a
4e53974
5c96ae4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1635,7 +1635,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) { | |
|
||
if (exc && PyErr_ExceptionMatches(PyExc_OverflowError)) { | ||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PRINTMARK(); | ||
goto INVALID; | ||
tc->type = JT_BIGNUM; | ||
} | ||
|
||
return; | ||
|
@@ -2126,6 +2126,15 @@ double Object_getDoubleValue(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) { | |
return GET_TC(tc)->doubleValue; | ||
} | ||
|
||
// /* | ||
const char *Object_getBigNumStringValue(JSOBJ obj, JSONTypeContext *tc) { | ||
// char wstr[100]; | ||
int sign = (obj<0) ? -1 : 1; | ||
arw2019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
printf("sign %d\n", sign); | ||
return GET_TC(tc)->cStr; | ||
} | ||
// */ | ||
|
||
static void Object_releaseObject(JSOBJ _obj) { Py_DECREF((PyObject *)_obj); } | ||
|
||
void Object_iterBegin(JSOBJ obj, JSONTypeContext *tc) { | ||
|
@@ -2179,6 +2188,7 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args, | |
Object_endTypeContext, | ||
Object_getStringValue, | ||
Object_getLongValue, | ||
Object_getBigNumStringValue, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line throws a compiler error:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will need to update the PyEncoder struct to have the appropriate member definitions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you can address this and the comment around the free call I think things will work leaking some memory but can continue to address that |
||
NULL, // getIntValue is unused | ||
Object_getDoubleValue, | ||
Object_iterBegin, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import locale | ||
import math | ||
import re | ||
import sys | ||
import time | ||
|
||
import dateutil | ||
|
@@ -559,6 +560,15 @@ def test_encode_long_conversion(self): | |
assert output == json.dumps(long_input) | ||
assert long_input == ujson.decode(output) | ||
|
||
def test_dumps_ints_larger_than_maxsize(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also add a full integration test in json/test_pandas.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also parametrize this to exceed the minimum supported native size There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do the parametrization of a large negative value here too? |
||
# GH34395 | ||
big_num = sys.maxsize + 1 | ||
encoding = ujson.dumps(big_num) | ||
|
||
assert str(encoding) == json.dumps(big_num) | ||
arw2019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# ujson.loads to be fixed in the future | ||
arw2019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# assert ujson.loads(encoding) == big_num | ||
|
||
@pytest.mark.parametrize( | ||
"int_exp", ["1337E40", "1.337E40", "1337E+9", "1.337e+40", "1.337E-4"] | ||
) | ||
|
Uh oh!
There was an error while loading. Please reload this page.