Skip to content

Commit

Permalink
REF: more greppable names for ujson functions (#54202)
Browse files Browse the repository at this point in the history
* REF: more greppable names for ujson functions

* update pyi file
  • Loading branch information
jbrockmendel committed Jul 20, 2023
1 parent bf75b20 commit be63ff5
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 186 deletions.
4 changes: 2 additions & 2 deletions pandas/_libs/json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import (
Callable,
)

def dumps(
def ujson_dumps(
obj: Any,
ensure_ascii: bool = ...,
double_precision: int = ...,
Expand All @@ -14,7 +14,7 @@ def dumps(
default_handler: None
| Callable[[Any], str | float | bool | list | dict | None] = ...,
) -> str: ...
def loads(
def ujson_loads(
s: str,
precise_float: bool = ...,
numpy: bool = ...,
Expand Down
9 changes: 2 additions & 7 deletions pandas/_libs/src/vendored/ujson/python/ujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,9 @@ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs);
"encode_html_chars=True to encode < > & as unicode escape sequences."

static PyMethodDef ujsonMethods[] = {
{"encode", (PyCFunction)objToJSON, METH_VARARGS | METH_KEYWORDS,
{"ujson_dumps", (PyCFunction)objToJSON, METH_VARARGS | METH_KEYWORDS,
"Converts arbitrary object recursively into JSON. " ENCODER_HELP_TEXT},
{"decode", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS,
"Converts JSON as string to dict object structure. Use precise_float=True "
"to use high precision float decoder."},
{"dumps", (PyCFunction)objToJSON, METH_VARARGS | METH_KEYWORDS,
"Converts arbitrary object recursively into JSON. " ENCODER_HELP_TEXT},
{"loads", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS,
{"ujson_loads", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS,
"Converts JSON as string to dict object structure. Use precise_float=True "
"to use high precision float decoder."},
{NULL, NULL, 0, NULL} /* Sentinel */
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_odswriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def _process_style(self, style: dict[str, Any]) -> str:

if style is None:
return None
style_key = json.dumps(style)
style_key = json.ujson_dumps(style)
if style_key in self._style_dict:
return self._style_dict[style_key]
name = f"pd{len(self._style_dict)+1}"
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/excel/_xlsxwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _write_cells(
for cell in cells:
val, fmt = self._value_with_fmt(cell.val)

stylekey = json.dumps(cell.style)
stylekey = json.ujson_dumps(cell.style)
if fmt:
stylekey += fmt

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/json/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pandas.io.json._json import (
dumps,
loads,
read_json,
to_json,
ujson_dumps as dumps,
ujson_loads as loads,
)
from pandas.io.json._table_schema import build_table_schema

Expand Down
16 changes: 8 additions & 8 deletions pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

from pandas._libs import lib
from pandas._libs.json import (
dumps,
loads,
ujson_dumps,
ujson_loads,
)
from pandas._libs.tslibs import iNaT
from pandas.compat._optional import import_optional_dependency
Expand Down Expand Up @@ -255,7 +255,7 @@ def _format_axes(self):

def write(self) -> str:
iso_dates = self.date_format == "iso"
return dumps(
return ujson_dumps(
self.obj_to_write,
orient=self.orient,
double_precision=self.double_precision,
Expand Down Expand Up @@ -1327,7 +1327,7 @@ class SeriesParser(Parser):
_split_keys = ("name", "index", "data")

def _parse(self) -> None:
data = loads(self.json, precise_float=self.precise_float)
data = ujson_loads(self.json, precise_float=self.precise_float)

if self.orient == "split":
decoded = {str(k): v for k, v in data.items()}
Expand Down Expand Up @@ -1356,12 +1356,12 @@ def _parse(self) -> None:

if orient == "columns":
self.obj = DataFrame(
loads(json, precise_float=self.precise_float), dtype=None
ujson_loads(json, precise_float=self.precise_float), dtype=None
)
elif orient == "split":
decoded = {
str(k): v
for k, v in loads(json, precise_float=self.precise_float).items()
for k, v in ujson_loads(json, precise_float=self.precise_float).items()
}
self.check_keys_split(decoded)
orig_names = [
Expand All @@ -1375,15 +1375,15 @@ def _parse(self) -> None:
self.obj = DataFrame(dtype=None, **decoded)
elif orient == "index":
self.obj = DataFrame.from_dict(
loads(json, precise_float=self.precise_float),
ujson_loads(json, precise_float=self.precise_float),
dtype=None,
orient="index",
)
elif orient == "table":
self.obj = parse_table_schema(json, precise_float=self.precise_float)
else:
self.obj = DataFrame(
loads(json, precise_float=self.precise_float), dtype=None
ujson_loads(json, precise_float=self.precise_float), dtype=None
)

def _process_converter(self, f, filt=None) -> None:
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/json/_table_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import warnings

from pandas._libs import lib
from pandas._libs.json import loads
from pandas._libs.json import ujson_loads
from pandas._libs.tslibs import timezones
from pandas.util._exceptions import find_stack_level

Expand Down Expand Up @@ -352,7 +352,7 @@ def parse_table_schema(json, precise_float: bool) -> DataFrame:
build_table_schema : Inverse function.
pandas.read_json
"""
table = loads(json, precise_float=precise_float)
table = ujson_loads(json, precise_float=precise_float)
col_order = [field["name"] for field in table["schema"]["fields"]]
df = DataFrame(table["data"], columns=col_order)[col_order]

Expand Down

0 comments on commit be63ff5

Please sign in to comment.