Skip to content

Commit be63ff5

Browse files
authored
REF: more greppable names for ujson functions (pandas-dev#54202)
* REF: more greppable names for ujson functions * update pyi file
1 parent bf75b20 commit be63ff5

File tree

8 files changed

+197
-186
lines changed

8 files changed

+197
-186
lines changed

pandas/_libs/json.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from typing import (
33
Callable,
44
)
55

6-
def dumps(
6+
def ujson_dumps(
77
obj: Any,
88
ensure_ascii: bool = ...,
99
double_precision: int = ...,
@@ -14,7 +14,7 @@ def dumps(
1414
default_handler: None
1515
| Callable[[Any], str | float | bool | list | dict | None] = ...,
1616
) -> str: ...
17-
def loads(
17+
def ujson_loads(
1818
s: str,
1919
precise_float: bool = ...,
2020
numpy: bool = ...,

pandas/_libs/src/vendored/ujson/python/ujson.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,9 @@ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs);
5454
"encode_html_chars=True to encode < > & as unicode escape sequences."
5555

5656
static PyMethodDef ujsonMethods[] = {
57-
{"encode", (PyCFunction)objToJSON, METH_VARARGS | METH_KEYWORDS,
57+
{"ujson_dumps", (PyCFunction)objToJSON, METH_VARARGS | METH_KEYWORDS,
5858
"Converts arbitrary object recursively into JSON. " ENCODER_HELP_TEXT},
59-
{"decode", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS,
60-
"Converts JSON as string to dict object structure. Use precise_float=True "
61-
"to use high precision float decoder."},
62-
{"dumps", (PyCFunction)objToJSON, METH_VARARGS | METH_KEYWORDS,
63-
"Converts arbitrary object recursively into JSON. " ENCODER_HELP_TEXT},
64-
{"loads", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS,
59+
{"ujson_loads", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS,
6560
"Converts JSON as string to dict object structure. Use precise_float=True "
6661
"to use high precision float decoder."},
6762
{NULL, NULL, 0, NULL} /* Sentinel */

pandas/io/excel/_odswriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def _process_style(self, style: dict[str, Any]) -> str:
247247

248248
if style is None:
249249
return None
250-
style_key = json.dumps(style)
250+
style_key = json.ujson_dumps(style)
251251
if style_key in self._style_dict:
252252
return self._style_dict[style_key]
253253
name = f"pd{len(self._style_dict)+1}"

pandas/io/excel/_xlsxwriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def _write_cells(
261261
for cell in cells:
262262
val, fmt = self._value_with_fmt(cell.val)
263263

264-
stylekey = json.dumps(cell.style)
264+
stylekey = json.ujson_dumps(cell.style)
265265
if fmt:
266266
stylekey += fmt
267267

pandas/io/json/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from pandas.io.json._json import (
2-
dumps,
3-
loads,
42
read_json,
53
to_json,
4+
ujson_dumps as dumps,
5+
ujson_loads as loads,
66
)
77
from pandas.io.json._table_schema import build_table_schema
88

pandas/io/json/_json.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
from pandas._libs import lib
2424
from pandas._libs.json import (
25-
dumps,
26-
loads,
25+
ujson_dumps,
26+
ujson_loads,
2727
)
2828
from pandas._libs.tslibs import iNaT
2929
from pandas.compat._optional import import_optional_dependency
@@ -255,7 +255,7 @@ def _format_axes(self):
255255

256256
def write(self) -> str:
257257
iso_dates = self.date_format == "iso"
258-
return dumps(
258+
return ujson_dumps(
259259
self.obj_to_write,
260260
orient=self.orient,
261261
double_precision=self.double_precision,
@@ -1327,7 +1327,7 @@ class SeriesParser(Parser):
13271327
_split_keys = ("name", "index", "data")
13281328

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

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

13571357
if orient == "columns":
13581358
self.obj = DataFrame(
1359-
loads(json, precise_float=self.precise_float), dtype=None
1359+
ujson_loads(json, precise_float=self.precise_float), dtype=None
13601360
)
13611361
elif orient == "split":
13621362
decoded = {
13631363
str(k): v
1364-
for k, v in loads(json, precise_float=self.precise_float).items()
1364+
for k, v in ujson_loads(json, precise_float=self.precise_float).items()
13651365
}
13661366
self.check_keys_split(decoded)
13671367
orig_names = [
@@ -1375,15 +1375,15 @@ def _parse(self) -> None:
13751375
self.obj = DataFrame(dtype=None, **decoded)
13761376
elif orient == "index":
13771377
self.obj = DataFrame.from_dict(
1378-
loads(json, precise_float=self.precise_float),
1378+
ujson_loads(json, precise_float=self.precise_float),
13791379
dtype=None,
13801380
orient="index",
13811381
)
13821382
elif orient == "table":
13831383
self.obj = parse_table_schema(json, precise_float=self.precise_float)
13841384
else:
13851385
self.obj = DataFrame(
1386-
loads(json, precise_float=self.precise_float), dtype=None
1386+
ujson_loads(json, precise_float=self.precise_float), dtype=None
13871387
)
13881388

13891389
def _process_converter(self, f, filt=None) -> None:

pandas/io/json/_table_schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import warnings
1414

1515
from pandas._libs import lib
16-
from pandas._libs.json import loads
16+
from pandas._libs.json import ujson_loads
1717
from pandas._libs.tslibs import timezones
1818
from pandas.util._exceptions import find_stack_level
1919

@@ -352,7 +352,7 @@ def parse_table_schema(json, precise_float: bool) -> DataFrame:
352352
build_table_schema : Inverse function.
353353
pandas.read_json
354354
"""
355-
table = loads(json, precise_float=precise_float)
355+
table = ujson_loads(json, precise_float=precise_float)
356356
col_order = [field["name"] for field in table["schema"]["fields"]]
357357
df = DataFrame(table["data"], columns=col_order)[col_order]
358358

0 commit comments

Comments
 (0)