Skip to content

Ensure accurate encoding/decoding of big and small floats #4042

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions pandas/io/tests/test_json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ def test_decimalDecodeTestPrecise(self):
decoded = ujson.decode(encoded, precise_float=True)
self.assertEqual(sut, decoded)

def test_decimalDecodeTestPreciseDoubleBig(self):
sut = {u'a': 4.56e300}
encoded = ujson.encode(sut)
decoded = ujson.decode(encoded, precise_float=True)
self.assertEqual(sut, decoded)

def test_decimalDecodeTestPreciseDoubleSmall(self):
sut = {u'a': 4.56e-300}
encoded = ujson.encode(sut)
decoded = ujson.decode(encoded, precise_float=True)
self.assertEqual(sut, decoded)

def test_decimalDecodeTestPreciseSingleBig(self):
sut = {u'a': 4.56e35}
encoded = ujson.encode(sut)
decoded = ujson.decode(encoded, precise_float=True)
self.assertEqual(sut, decoded)

def test_decimalDecodeTestPreciseSingleSmall(self):
sut = {u'a': 4.56e-35}
encoded = ujson.encode(sut)
decoded = ujson.decode(encoded, precise_float=True)
self.assertEqual(sut, decoded)

def test_encodeDictWithUnicodeKeys(self):
input = { u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1", u"key1": u"value1" }
output = ujson.encode(input)
Expand Down Expand Up @@ -1416,6 +1440,26 @@ def test_decodeFloatingPointAdditionalTests(self):
self.assertEquals(1.893, ujson.loads("1.893"))
self.assertEquals(1.3, ujson.loads("1.3"))

self.assertEquals(1.1234567893e-300, ujson.loads("1.1234567893e-300"))
self.assertEquals(1.234567893e-300, ujson.loads("1.234567893e-300"))
self.assertEquals(1.34567893e-300, ujson.loads("1.34567893e-300"))
self.assertEquals(1.4567893e-300, ujson.loads("1.4567893e-300"))
self.assertEquals(1.567893e-300, ujson.loads("1.567893e-300"))
self.assertEquals(1.67893e-300, ujson.loads("1.67893e-300"))
self.assertEquals(1.7893e-300, ujson.loads("1.7893e-300"))
self.assertEquals(1.893e-300, ujson.loads("1.893e-300"))
self.assertEquals(1.3e-300, ujson.loads("1.3e-300"))

self.assertEquals(1.1234567893e300, ujson.loads("1.1234567893e300"))
self.assertEquals(1.234567893e300, ujson.loads("1.234567893e300"))
self.assertEquals(1.34567893e300, ujson.loads("1.34567893e300"))
self.assertEquals(1.4567893e300, ujson.loads("1.4567893e300"))
self.assertEquals(1.567893e300, ujson.loads("1.567893e300"))
self.assertEquals(1.67893e300, ujson.loads("1.67893e300"))
self.assertEquals(1.7893e300, ujson.loads("1.7893e300"))
self.assertEquals(1.893e300, ujson.loads("1.893e300"))
self.assertEquals(1.3e300, ujson.loads("1.3e300"))

def test_encodeBigSet(self):
s = set()
for x in xrange(0, 100000):
Expand Down