Skip to content

STYLE: #49656 - generic.py #49960

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 9 commits into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import collections
import datetime as dt
import gc
import json
from json import loads
import operator
import pickle
import re
Expand Down Expand Up @@ -134,7 +134,6 @@
algorithms as algos,
arraylike,
indexing,
missing,
nanops,
sample,
)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2410,16 +2413,16 @@ def to_json(

Examples
--------
>>> import json
>>> from json import loads, dumps
>>> df = pd.DataFrame(
... [["a", "b"], ["c", "d"]],
... index=["row 1", "row 2"],
... columns=["col 1", "col 2"],
... )

>>> 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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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": [
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down