Skip to content

Commit ea57d98

Browse files
committed
Code review - I
- json_normalize --> _json_normalize - json_normalize inside io.json._normalize is a deprecated method - update whatsnew docs - update io docs - fix broken test_api
1 parent ad922ce commit ea57d98

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

doc/source/user_guide/io.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ into a flat table.
21502150

21512151
.. ipython:: python
21522152
2153-
from pandas.io.json import json_normalize
2153+
from pandas import json_normalize
21542154
data = [{'id': 1, 'name': {'first': 'Coleen', 'last': 'Volk'}},
21552155
{'name': {'given': 'Mose', 'family': 'Regner'}},
21562156
{'id': 2, 'name': 'Faye Raker'}]

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Other API changes
5252

5353
Deprecations
5454
~~~~~~~~~~~~
55-
- Moved :func:`pandas.io.json.json_normalize` to the top-level namespace as :func:`pandas.json_normalize`.
55+
- :func:`pandas.json_normalize` is now exposed in the top-level namespace. Usage of :func:`json_normalize` as :func:`pandas.io.json.json_normalize` is now deprecated and it is recommended to use :func:`json_normalize` as :func:`pandas.json_normalize` instead. (:issue:`27586`)
5656
-
5757
-
5858

pandas/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
)
180180

181181
from pandas.io.json import (
182-
json_normalize
182+
_json_normalize as json_normalize
183183
)
184184

185185
from pandas.util._tester import test

pandas/io/json/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from pandas.io.json._json import dumps, loads, read_json, to_json
2-
from pandas.io.json._normalize import json_normalize
2+
from pandas.io.json._normalize import _json_normalize, json_normalize
33
from pandas.io.json._table_schema import build_table_schema
44

55
__all__ = [
66
"dumps",
77
"loads",
88
"read_json",
99
"to_json",
10+
"_json_normalize",
1011
"json_normalize",
1112
"build_table_schema",
1213
]

pandas/io/json/_normalize.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pandas._libs.writers import convert_json_to_lines
1111

1212
from pandas import DataFrame
13+
from pandas.util._decorators import deprecate
1314

1415

1516
def convert_to_line_delimits(s):
@@ -111,7 +112,7 @@ def nested_to_record(
111112
return new_ds
112113

113114

114-
def json_normalize(
115+
def _json_normalize(
115116
data: Union[Dict, List[Dict]],
116117
record_path: Optional[Union[str, List]] = None,
117118
meta: Optional[Union[str, List]] = None,
@@ -341,3 +342,11 @@ def _recursive_extract(data, path, seen_meta, level=0):
341342
)
342343
result[k] = np.array(v, dtype=object).repeat(lengths)
343344
return result
345+
346+
347+
json_normalize = deprecate(
348+
"pandas.io.json.json_normalize",
349+
_json_normalize,
350+
"1.0.0",
351+
"pandas.json_normalize",
352+
)

pandas/tests/api/test_api.py

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class TestPDApi(Base):
168168
"read_spss",
169169
]
170170

171+
# top-level json funcs
172+
funcs_json = ["json_normalize"]
173+
171174
# top-level to_* funcs
172175
funcs_to = ["to_datetime", "to_msgpack", "to_numeric", "to_pickle", "to_timedelta"]
173176

0 commit comments

Comments
 (0)