diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1b17deb7def90..2de83bb7a4468 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4,7 +4,7 @@ import collections import datetime as dt import gc -import json +from json import loads import operator import pickle import re @@ -134,7 +134,6 @@ algorithms as algos, arraylike, indexing, - missing, nanops, sample, ) @@ -160,7 +159,11 @@ SingleArrayManager, ) from pandas.core.internals.construction import mgr_to_mgr -from pandas.core.missing import find_valid_index +from pandas.core.missing import ( + clean_fill_method, + clean_reindex_fill_method, + find_valid_index, +) from pandas.core.ops import align_method_FRAME from pandas.core.reshape.concat import concat from pandas.core.shared_docs import _shared_docs @@ -2122,7 +2125,7 @@ def _repr_data_resource_(self): as_json = data.to_json(orient="table") as_json = cast(str, as_json) - return json.loads(as_json, object_pairs_hook=collections.OrderedDict) + return loads(as_json, object_pairs_hook=collections.OrderedDict) # ---------------------------------------------------------------------- # I/O Methods @@ -2410,7 +2413,7 @@ def to_json( Examples -------- - >>> import json + >>> from json import loads, dumps >>> df = pd.DataFrame( ... [["a", "b"], ["c", "d"]], ... index=["row 1", "row 2"], @@ -2418,8 +2421,8 @@ def to_json( ... ) >>> result = df.to_json(orient="split") - >>> parsed = json.loads(result) - >>> json.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "columns": [ "col 1", @@ -2445,8 +2448,8 @@ def to_json( Note that index labels are not preserved with this encoding. >>> result = df.to_json(orient="records") - >>> parsed = json.loads(result) - >>> json.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP [ {{ "col 1": "a", @@ -2461,8 +2464,8 @@ def to_json( Encoding/decoding a Dataframe using ``'index'`` formatted JSON: >>> result = df.to_json(orient="index") - >>> parsed = json.loads(result) - >>> json.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "row 1": {{ "col 1": "a", @@ -2477,8 +2480,8 @@ def to_json( Encoding/decoding a Dataframe using ``'columns'`` formatted JSON: >>> result = df.to_json(orient="columns") - >>> parsed = json.loads(result) - >>> json.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "col 1": {{ "row 1": "a", @@ -2493,8 +2496,8 @@ def to_json( Encoding/decoding a Dataframe using ``'values'`` formatted JSON: >>> result = df.to_json(orient="values") - >>> parsed = json.loads(result) - >>> json.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP [ [ "a", @@ -2509,8 +2512,8 @@ def to_json( Encoding with Table Schema: >>> result = df.to_json(orient="table") - >>> parsed = json.loads(result) - >>> json.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "schema": {{ "fields": [ @@ -5169,7 +5172,7 @@ def reindex(self: NDFrameT, *args, **kwargs) -> NDFrameT: # construct the args axes, kwargs = self._construct_axes_from_arguments(args, kwargs) - method = missing.clean_reindex_fill_method(kwargs.pop("method", None)) + method = clean_reindex_fill_method(kwargs.pop("method", None)) level = kwargs.pop("level", None) copy = kwargs.pop("copy", None) limit = kwargs.pop("limit", None) @@ -9201,7 +9204,7 @@ def align( 4 600.0 700.0 800.0 900.0 NaN """ - method = missing.clean_fill_method(method) + method = clean_fill_method(method) if broadcast_axis == 1 and self.ndim != other.ndim: if isinstance(self, ABCSeries):