Skip to content

ujson Py2 compat removal #26199

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 8 commits into from
Apr 24, 2019
Merged

ujson Py2 compat removal #26199

merged 8 commits into from
Apr 24, 2019

Conversation

WillAyd
Copy link
Member

@WillAyd WillAyd commented Apr 23, 2019

There was a header file in the ujson source specifically meant to bridge compatibility between Py2 and Py3. With the Py2 support drop this could be removed and the source code simplified.

Most of these changes are simply verbatim, though there are probably a few follow ups on context to simplify further that could be made

@WillAyd WillAyd added IO JSON read_json, to_json, json_normalize 2/3 Compat Clean labels Apr 23, 2019
#define PY_ARRAY_UNIQUE_SYMBOL UJSON_NUMPY
#define NO_IMPORT_ARRAY
#include <numpy/arrayobject.h> // NOLINT(build/include_order)
#include <ultrajson.h> // NOLINT(build/include_order)
#define PY_SSIZE_T_CLEAN
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 definition is suggested by the Python developers:

https://docs.python.org/3/c-api/intro.html#include-files

I noticed we haven't used anywhere else so could probably be added as a follow up in other places

#include <numpy/arrayscalars.h> // NOLINT(build/include_order)
#include <numpy/ndarraytypes.h> // NOLINT(build/include_order)
#include <numpy/npy_math.h> // NOLINT(build/include_order)
#include <stdio.h> // NOLINT(build/include_order)
Copy link
Member Author

Choose a reason for hiding this comment

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

#include <Python.h> implies this so no need to state again

@codecov
Copy link

codecov bot commented Apr 23, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26199      +/-   ##
==========================================
- Coverage   91.98%   91.98%   -0.01%     
==========================================
  Files         175      175              
  Lines       52372    52372              
==========================================
- Hits        48176    48172       -4     
- Misses       4196     4200       +4
Flag Coverage Δ
#multiple 90.53% <ø> (ø) ⬆️
#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 d74901b...1d76085. Read the comment docs.

@codecov
Copy link

codecov bot commented Apr 23, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26199      +/-   ##
==========================================
- Coverage   91.98%   91.98%   -0.01%     
==========================================
  Files         175      175              
  Lines       52372    52372              
==========================================
- Hits        48177    48173       -4     
- Misses       4195     4199       +4
Flag Coverage Δ
#multiple 90.53% <ø> (ø) ⬆️
#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 b62e9ae...6a17247. Read the comment docs.

@jreback jreback added this to the 0.25.0 milestone Apr 24, 2019
@@ -530,7 +528,7 @@ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs) {
decoder->preciseFloat = 1;
}

if (PyString_Check(arg)) {
if (PyBytes_Check(arg)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

so if this is correct then the error message is wrong? should be bytes or unicode? is there something that hits this in testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the error message and added a test to test_ujson. FWIW I don't think anything user-facing hits this as doing:

pd.read_json(None)

Would yield:

>>> pd.read_json(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/williamayd/clones/pandas/pandas/io/json/json.py", line 437, in read_json
    path_or_buf, encoding=encoding, compression=compression,
  File "/Users/williamayd/clones/pandas/pandas/io/common.py", line 207, in get_filepath_or_buffer
    raise ValueError(msg.format(_type=type(filepath_or_buffer)))
ValueError: Invalid file path or buffer object type: <class 'NoneType'>

You could hit it directly internally if you did something like:

import pandas._libs.json as ujson
ujson.loads(None)

which now yields:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Expected 'str' or 'bytes'

@jreback jreback merged commit 4d9de8d into pandas-dev:master Apr 24, 2019
@jreback
Copy link
Contributor

jreback commented Apr 24, 2019

thanks @WillAyd

@WillAyd WillAyd deleted the remove-pydefines branch April 25, 2019 15:57
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.

2 participants