From 0e3b4d48f12b75b6cda1aecfe2bd0428b98dd8a1 Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Mon, 28 Nov 2022 21:16:11 -0800 Subject: [PATCH 1/7] Update format.py --- pandas/io/formats/format.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index cdc21f04da43a..cbb56e2d19cc0 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -9,7 +9,7 @@ QUOTE_NONE, QUOTE_NONNUMERIC, ) -import decimal +import decimal as dec from functools import partial from io import StringIO import math @@ -108,7 +108,7 @@ ) from pandas.io.formats.printing import ( adjoin, - justify, + justify as jtf, pprint_thing, ) @@ -433,7 +433,7 @@ def len(self, text: str) -> int: return len(text) def justify(self, texts: Any, max_len: int, mode: str = "right") -> list[str]: - return justify(texts, max_len, mode=mode) + return jtf(texts, max_len, mode=mode) def adjoin(self, space: int, *lists, **kwargs) -> str: return adjoin(space, *lists, strlen=self.len, justfunc=self.justify, **kwargs) @@ -1794,12 +1794,12 @@ def _format_datetime64_dateonly( def get_format_datetime64( - is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None + dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None ) -> Callable: """Return a formatter callable taking a datetime64 as input and providing a string as output""" - if is_dates_only: + if dates_only: return lambda x: _format_datetime64_dateonly( x, nat_rep=nat_rep, date_format=date_format ) @@ -2071,12 +2071,12 @@ def __call__(self, num: float) -> str: @return: engineering formatted string """ - dnum = decimal.Decimal(str(num)) + dnum = dec.Decimal(str(num)) - if decimal.Decimal.is_nan(dnum): + if dec.Decimal.is_nan(dnum): return "NaN" - if decimal.Decimal.is_infinite(dnum): + if dec.Decimal.is_infinite(dnum): return "inf" sign = 1 @@ -2086,9 +2086,9 @@ def __call__(self, num: float) -> str: dnum = -dnum if dnum != 0: - pow10 = decimal.Decimal(int(math.floor(dnum.log10() / 3) * 3)) + pow10 = dec.Decimal(int(math.floor(dnum.log10() / 3) * 3)) else: - pow10 = decimal.Decimal(0) + pow10 = dec.Decimal(0) pow10 = pow10.min(max(self.ENG_PREFIXES.keys())) pow10 = pow10.max(min(self.ENG_PREFIXES.keys())) From 5c3863d1ed8dc6878f07661a33a425f0341fe276 Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Mon, 28 Nov 2022 22:01:28 -0800 Subject: [PATCH 2/7] Update format.py 9.99/10 --- pandas/io/formats/format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index cbb56e2d19cc0..24c701bdca448 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1794,12 +1794,12 @@ def _format_datetime64_dateonly( def get_format_datetime64( - dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None + is_dates_only: bool, nat_rep: str = "NaT", date_format: str | None = None ) -> Callable: """Return a formatter callable taking a datetime64 as input and providing a string as output""" - if dates_only: + if is_dates_only: return lambda x: _format_datetime64_dateonly( x, nat_rep=nat_rep, date_format=date_format ) From db2ec7fcce7c0c77003cb6798878df5cba16648a Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 29 Nov 2022 12:40:06 -0800 Subject: [PATCH 3/7] Update generic.py --- pandas/core/generic.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1b17deb7def90..f68426a11cfc7 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 +import json as js import operator import pickle import re @@ -134,7 +134,7 @@ algorithms as algos, arraylike, indexing, - missing, + missing as miss, nanops, sample, ) @@ -2122,7 +2122,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 js.loads(as_json, object_pairs_hook=collections.OrderedDict) # ---------------------------------------------------------------------- # I/O Methods @@ -2410,7 +2410,7 @@ def to_json( Examples -------- - >>> import json + >>> import json as js >>> df = pd.DataFrame( ... [["a", "b"], ["c", "d"]], ... index=["row 1", "row 2"], @@ -2418,8 +2418,8 @@ def to_json( ... ) >>> result = df.to_json(orient="split") - >>> parsed = json.loads(result) - >>> json.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = js.loads(result) + >>> js.dumps(parsed, indent=4) # doctest: +SKIP {{ "columns": [ "col 1", @@ -2445,8 +2445,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 = js.loads(result) + >>> js.dumps(parsed, indent=4) # doctest: +SKIP [ {{ "col 1": "a", @@ -2461,8 +2461,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 = js.loads(result) + >>> js.dumps(parsed, indent=4) # doctest: +SKIP {{ "row 1": {{ "col 1": "a", @@ -2477,8 +2477,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 = js.loads(result) + >>> js.dumps(parsed, indent=4) # doctest: +SKIP {{ "col 1": {{ "row 1": "a", @@ -2493,8 +2493,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 = js.loads(result) + >>> js.dumps(parsed, indent=4) # doctest: +SKIP [ [ "a", @@ -2509,8 +2509,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 = js.loads(result) + >>> js.dumps(parsed, indent=4) # doctest: +SKIP {{ "schema": {{ "fields": [ @@ -5169,7 +5169,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 = miss.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 +9201,7 @@ def align( 4 600.0 700.0 800.0 900.0 NaN """ - method = missing.clean_fill_method(method) + method = miss.clean_fill_method(method) if broadcast_axis == 1 and self.ndim != other.ndim: if isinstance(self, ABCSeries): From 9d6b42139d4f55cb5a594bffc40cc5a94389d96a Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 29 Nov 2022 12:44:40 -0800 Subject: [PATCH 4/7] Return format.py --- pandas/io/formats/format.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 24c701bdca448..cdc21f04da43a 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -9,7 +9,7 @@ QUOTE_NONE, QUOTE_NONNUMERIC, ) -import decimal as dec +import decimal from functools import partial from io import StringIO import math @@ -108,7 +108,7 @@ ) from pandas.io.formats.printing import ( adjoin, - justify as jtf, + justify, pprint_thing, ) @@ -433,7 +433,7 @@ def len(self, text: str) -> int: return len(text) def justify(self, texts: Any, max_len: int, mode: str = "right") -> list[str]: - return jtf(texts, max_len, mode=mode) + return justify(texts, max_len, mode=mode) def adjoin(self, space: int, *lists, **kwargs) -> str: return adjoin(space, *lists, strlen=self.len, justfunc=self.justify, **kwargs) @@ -2071,12 +2071,12 @@ def __call__(self, num: float) -> str: @return: engineering formatted string """ - dnum = dec.Decimal(str(num)) + dnum = decimal.Decimal(str(num)) - if dec.Decimal.is_nan(dnum): + if decimal.Decimal.is_nan(dnum): return "NaN" - if dec.Decimal.is_infinite(dnum): + if decimal.Decimal.is_infinite(dnum): return "inf" sign = 1 @@ -2086,9 +2086,9 @@ def __call__(self, num: float) -> str: dnum = -dnum if dnum != 0: - pow10 = dec.Decimal(int(math.floor(dnum.log10() / 3) * 3)) + pow10 = decimal.Decimal(int(math.floor(dnum.log10() / 3) * 3)) else: - pow10 = dec.Decimal(0) + pow10 = decimal.Decimal(0) pow10 = pow10.min(max(self.ENG_PREFIXES.keys())) pow10 = pow10.max(min(self.ENG_PREFIXES.keys())) From 5939668d0c759d910084aff126bfbc63d68fcb84 Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:01:21 -0800 Subject: [PATCH 5/7] Update generic.py --- pandas/core/generic.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f68426a11cfc7..ebe047d2f80d2 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 as js +from json import loads, jumps import operator import pickle import re @@ -134,7 +134,6 @@ algorithms as algos, arraylike, indexing, - missing as miss, nanops, sample, ) @@ -160,7 +159,7 @@ SingleArrayManager, ) from pandas.core.internals.construction import mgr_to_mgr -from pandas.core.missing import find_valid_index +from pandas.core.missing import find_valid_index, clean_reindex_fill_method, clean_fill_method 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 +2121,7 @@ def _repr_data_resource_(self): as_json = data.to_json(orient="table") as_json = cast(str, as_json) - return js.loads(as_json, object_pairs_hook=collections.OrderedDict) + return loads(as_json, object_pairs_hook=collections.OrderedDict) # ---------------------------------------------------------------------- # I/O Methods @@ -2410,7 +2409,7 @@ def to_json( Examples -------- - >>> import json as js + >>> from json import loads, dumps >>> df = pd.DataFrame( ... [["a", "b"], ["c", "d"]], ... index=["row 1", "row 2"], @@ -2418,8 +2417,8 @@ def to_json( ... ) >>> result = df.to_json(orient="split") - >>> parsed = js.loads(result) - >>> js.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "columns": [ "col 1", @@ -2445,8 +2444,8 @@ def to_json( Note that index labels are not preserved with this encoding. >>> result = df.to_json(orient="records") - >>> parsed = js.loads(result) - >>> js.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP [ {{ "col 1": "a", @@ -2461,8 +2460,8 @@ def to_json( Encoding/decoding a Dataframe using ``'index'`` formatted JSON: >>> result = df.to_json(orient="index") - >>> parsed = js.loads(result) - >>> js.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "row 1": {{ "col 1": "a", @@ -2477,8 +2476,8 @@ def to_json( Encoding/decoding a Dataframe using ``'columns'`` formatted JSON: >>> result = df.to_json(orient="columns") - >>> parsed = js.loads(result) - >>> js.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "col 1": {{ "row 1": "a", @@ -2493,8 +2492,8 @@ def to_json( Encoding/decoding a Dataframe using ``'values'`` formatted JSON: >>> result = df.to_json(orient="values") - >>> parsed = js.loads(result) - >>> js.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP [ [ "a", @@ -2509,8 +2508,8 @@ def to_json( Encoding with Table Schema: >>> result = df.to_json(orient="table") - >>> parsed = js.loads(result) - >>> js.dumps(parsed, indent=4) # doctest: +SKIP + >>> parsed = loads(result) + >>> dumps(parsed, indent=4) # doctest: +SKIP {{ "schema": {{ "fields": [ @@ -5169,7 +5168,7 @@ def reindex(self: NDFrameT, *args, **kwargs) -> NDFrameT: # construct the args axes, kwargs = self._construct_axes_from_arguments(args, kwargs) - method = miss.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 +9200,7 @@ def align( 4 600.0 700.0 800.0 900.0 NaN """ - method = miss.clean_fill_method(method) + method = clean_fill_method(method) if broadcast_axis == 1 and self.ndim != other.ndim: if isinstance(self, ABCSeries): From d26d13a9b64aa1e2431389099c54795a45880c9f Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:16:55 -0800 Subject: [PATCH 6/7] Update generic.py based on request change --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ebe047d2f80d2..e9bc8a744c3f0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4,7 +4,7 @@ import collections import datetime as dt import gc -from json import loads, jumps +from json import loads, dumps import operator import pickle import re From 9e7c9babd2c513debba8f03779f6e00877ba3994 Mon Sep 17 00:00:00 2001 From: bang128 <71242233+bang128@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:55:05 -0800 Subject: [PATCH 7/7] Done pre-commit --- pandas/core/generic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e9bc8a744c3f0..2de83bb7a4468 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4,7 +4,7 @@ import collections import datetime as dt import gc -from json import loads, dumps +from json import loads import operator import pickle import re @@ -159,7 +159,11 @@ SingleArrayManager, ) from pandas.core.internals.construction import mgr_to_mgr -from pandas.core.missing import find_valid_index, clean_reindex_fill_method, clean_fill_method +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