Skip to content

Continued ujson cleanups #26222

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

Merged
merged 3 commits into from
Apr 30, 2019
Merged

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Apr 26, 2019

ref some of the comments by @jbrockmendel in #26212

@WillAyd WillAyd added IO JSON read_json, to_json, json_normalize Clean labels Apr 26, 2019
#define NPY_JSON_BUFSIZE 32768

static PyTypeObject *type_decimal;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously a static PyObject, but the CPython guide says you should never declare static PyObjects. Swapped over to PyTypeObject to match semantics of others in the extension:

https://docs.python.org/3/c-api/intro.html#objects-types-and-reference-counts

@@ -628,44 +627,39 @@ void NpyArr_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
obj = (PyArrayObject *)_obj;
}

if (PyArray_SIZE(obj) < 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch of the condition was unreachable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shoyer is there some special case this might have been intended for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the context here, but I agree that this was unreachable.

Maybe it was intended to cover size 0 arrays, may not be representable in JSON? e.g., an shape with shape (0, 1)

@@ -1750,17 +1744,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
goto INVALID;
}

return;
} else if (PyLong_Check(obj)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unreachable; this used to be PyInt_Check so could yield something in Python2, but with switch to Python3 was duplicative of the PyLong_Check that immediately preceded it

@codecov
Copy link

codecov bot commented Apr 26, 2019

Codecov Report

Merging #26222 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26222      +/-   ##
==========================================
- Coverage   91.97%   91.97%   -0.01%     
==========================================
  Files         175      175              
  Lines       52379    52379              
==========================================
- Hits        48178    48174       -4     
- Misses       4201     4205       +4
Flag Coverage Δ
#multiple 90.52% <ø> (ø) ⬆️
#single 40.7% <ø> (-0.15%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 96.9% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65466f0...2f478f9. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Apr 26, 2019

Codecov Report

Merging #26222 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26222      +/-   ##
==========================================
- Coverage   91.97%   91.97%   -0.01%     
==========================================
  Files         175      175              
  Lines       52379    52379              
==========================================
- Hits        48178    48174       -4     
- Misses       4201     4205       +4
Flag Coverage Δ
#multiple 90.52% <ø> (ø) ⬆️
#single 40.7% <ø> (-0.15%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 96.9% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65466f0...2f478f9. Read the comment docs.

@@ -1782,7 +1765,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
pc->PyTypeToJSON = PyUnicodeToUTF8;
tc->type = JT_UTF8;
return;
} else if (PyObject_IsInstance(obj, type_decimal)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any Decimal subclasses to worry about?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyObject_TypeCheck returns true for subtypes as well, so I don't think that matters:

https://docs.python.org/3.7/c-api/object.html#c.PyObject_TypeCheck

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have sufficient tests with serializing Decimal?

@WillAyd
Copy link
Member Author

WillAyd commented Apr 29, 2019

All of the decimal tests are located here:

def test_encode_decimal(self):

They don't appear in anything user-facing but are covered in the encode/decode round tripping that this would effect.

If Decimal subclasses are a concern can also parametrize that test for Decimal and an arbitrary subclass. Let me know.

@jreback jreback added this to the 0.25.0 milestone Apr 30, 2019
@jreback jreback merged commit 66d6023 into pandas-dev:master Apr 30, 2019
@jreback
Copy link
Contributor

jreback commented Apr 30, 2019

thanks @WillAyd

@WillAyd WillAyd deleted the more-ujson-cleanups branch January 16, 2020 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants