From 7bef135d52ebc4604872fb3e9d4427b57fd326d9 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sun, 25 Jul 2021 09:54:20 +0100 Subject: [PATCH 01/20] doctest fix for #42671 --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 83e0086958b9a..fda87b6faaff5 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1956,7 +1956,7 @@ def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: - + >>> format_eng = EngFormatter() >>> format_eng(0) # for self.accuracy = 0 ' 0' From cc55377b56393994e22c1279556de3ef7532d897 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Sun, 25 Jul 2021 14:26:59 +0100 Subject: [PATCH 02/20] doctest fix for #42671(added format.py to doctest scripts) --- ci/code_checks.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 9f59958b4e827..51119773a4398 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -121,7 +121,8 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pandas/io/parsers/ \ pandas/io/sas/ \ pandas/io/sql.py \ - pandas/tseries/ + pandas/tseries/ \ + pandas/io/formats/format.py RET=$(($RET + $?)) ; echo $MSG "DONE" fi From e7a5a911af980c18a8378bd58bac6490e0a2a741 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Mon, 26 Jul 2021 12:22:06 +0100 Subject: [PATCH 03/20] doctest fix for #42670 --- pandas/io/formats/format.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index fda87b6faaff5..65ab5f2cb3cc0 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1952,7 +1952,7 @@ def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False): self.accuracy = accuracy self.use_eng_prefix = use_eng_prefix - def __call__(self, num: int | float) -> str: + def __call__(self, num: int | float) -> int: """ Formats a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: @@ -1983,6 +1983,9 @@ def __call__(self, num: int | float) -> str: return "inf" sign = 1 + if dnum == 0: + formatted = 0 + return formatted if dnum < 0: # pragma: no cover sign = -1 From 170cc45e894d924c4b8be47571dba90f793606ef Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Mon, 26 Jul 2021 12:49:14 +0100 Subject: [PATCH 04/20] doctest fix for #42670 (whitespace removal) --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 65ab5f2cb3cc0..a931626c5a813 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1958,7 +1958,7 @@ def __call__(self, num: int | float) -> int: representing the power of 1000 of the original number. Some examples: >>> format_eng = EngFormatter() >>> format_eng(0) # for self.accuracy = 0 - ' 0' + '0' >>> format_eng(1000000) # for self.accuracy = 1, # self.use_eng_prefix = True From fad0bab47b421e2f481bc7b0994d992122c54cf0 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Mon, 26 Jul 2021 12:54:18 +0100 Subject: [PATCH 05/20] doctest fix for #42670 --- pandas/io/formats/format.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index a931626c5a813..3bac2b149cf60 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1952,13 +1952,13 @@ def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False): self.accuracy = accuracy self.use_eng_prefix = use_eng_prefix - def __call__(self, num: int | float) -> int: + def __call__(self, num: int | float) ->str: """ Formats a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: >>> format_eng = EngFormatter() >>> format_eng(0) # for self.accuracy = 0 - '0' + ' 0' >>> format_eng(1000000) # for self.accuracy = 1, # self.use_eng_prefix = True @@ -1984,7 +1984,7 @@ def __call__(self, num: int | float) -> int: sign = 1 if dnum == 0: - formatted = 0 + formatted = ' 0' return formatted if dnum < 0: # pragma: no cover From a340b164e14e38c2ee728872e58c345750f739ee Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Mon, 26 Jul 2021 13:17:15 +0100 Subject: [PATCH 06/20] doctest fix for #42670 (reverted formatting changes pycharm auto formatted by accident) --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 3bac2b149cf60..ba4563ceaa98c 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1952,7 +1952,7 @@ def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False): self.accuracy = accuracy self.use_eng_prefix = use_eng_prefix - def __call__(self, num: int | float) ->str: + def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter representing the power of 1000 of the original number. Some examples: From 93d556529199281ccca683bde438e6fdbfbcc2fb Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 09:20:20 +0100 Subject: [PATCH 07/20] doctest fix for #42670 --- pandas/io/formats/format.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index ba4563ceaa98c..19c24405b5df4 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1955,17 +1955,17 @@ def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False): def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter - representing the power of 1000 of the original number. Some examples: - >>> format_eng = EngFormatter() - >>> format_eng(0) # for self.accuracy = 0 + representing the power of 10 of the original number. Some examples: + >>> format_eng = EngFormatter(0) + >>> format_eng(0) ' 0' + >>> format_eng = EngFormatter(1, True ) + >>> format_eng(1000000) - >>> format_eng(1000000) # for self.accuracy = 1, - # self.use_eng_prefix = True ' 1.0M' + >>> format_eng = EngFormatter(2, False) + >>> format_eng("-1e-6") - >>> format_eng("-1e-6") # for self.accuracy = 2 - # self.use_eng_prefix = False '-1.00E-06' @param num: the value to represent @@ -1983,9 +1983,6 @@ def __call__(self, num: int | float) -> str: return "inf" sign = 1 - if dnum == 0: - formatted = ' 0' - return formatted if dnum < 0: # pragma: no cover sign = -1 From 3074c66ba82dc70a4c8031c60e51b3a549c34c1c Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 09:39:50 +0100 Subject: [PATCH 08/20] doctest fix for #42670 --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 19c24405b5df4..edf0167c5510c 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1956,7 +1956,7 @@ def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter representing the power of 10 of the original number. Some examples: - >>> format_eng = EngFormatter(0) + >>> format_eng = EngFormatter(0, False) >>> format_eng(0) ' 0' >>> format_eng = EngFormatter(1, True ) From f5756cefa9871b537710602bdd6a52795cda3067 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 09:43:24 +0100 Subject: [PATCH 09/20] doctest fix for #42670 --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 19c24405b5df4..edf0167c5510c 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1956,7 +1956,7 @@ def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter representing the power of 10 of the original number. Some examples: - >>> format_eng = EngFormatter(0) + >>> format_eng = EngFormatter(0, False) >>> format_eng(0) ' 0' >>> format_eng = EngFormatter(1, True ) From 2ddfc4c62f08761991defd062677243eea3900a9 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 10:22:07 +0100 Subject: [PATCH 10/20] doctest fix for #42670 + EngFormatter code fix --- pandas/io/formats/format.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index edf0167c5510c..8f7fdd95bba22 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1956,14 +1956,14 @@ def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter representing the power of 10 of the original number. Some examples: - >>> format_eng = EngFormatter(0, False) + >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix = False) >>> format_eng(0) ' 0' - >>> format_eng = EngFormatter(1, True ) + >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix = True ) >>> format_eng(1000000) ' 1.0M' - >>> format_eng = EngFormatter(2, False) + >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix = False) >>> format_eng("-1e-6") '-1.00E-06' @@ -1984,6 +1984,10 @@ def __call__(self, num: int | float) -> str: sign = 1 + if dnum == 0: + formatted = ' 0' + return formatted + if dnum < 0: # pragma: no cover sign = -1 dnum = -dnum From eb44c51fbcc1beb8d84e1fa9de0a44e1b099e2ba Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 10:53:32 +0100 Subject: [PATCH 11/20] doctest fix for #42670 --- pandas/io/formats/format.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 8f7fdd95bba22..b48b4c9000d66 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1961,11 +1961,9 @@ def __call__(self, num: int | float) -> str: ' 0' >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix = True ) >>> format_eng(1000000) - ' 1.0M' >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix = False) >>> format_eng("-1e-6") - '-1.00E-06' @param num: the value to represent From 8f8763eb3bff3492c5e63c6a442c96aefe48ae7d Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 11:07:57 +0100 Subject: [PATCH 12/20] doctest fix for #42670 linting --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index b48b4c9000d66..59a7f349392b8 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1983,7 +1983,7 @@ def __call__(self, num: int | float) -> str: sign = 1 if dnum == 0: - formatted = ' 0' + formatted = " 0" return formatted if dnum < 0: # pragma: no cover From 2ab00ac550b8d582f9092aaf54d0d82527e0d974 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 11:18:10 +0100 Subject: [PATCH 13/20] doctest fix for #42670 --- pandas/io/formats/format.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 59a7f349392b8..82cec3eca5ddc 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1982,10 +1982,6 @@ def __call__(self, num: int | float) -> str: sign = 1 - if dnum == 0: - formatted = " 0" - return formatted - if dnum < 0: # pragma: no cover sign = -1 dnum = -dnum From 1a08c3e667b1e96b9b2377b64ec07ed1ff5eed8e Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 11:41:13 +0100 Subject: [PATCH 14/20] doctest fix for #42670 --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 82cec3eca5ddc..ba7f8674793d6 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1956,7 +1956,7 @@ def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter representing the power of 10 of the original number. Some examples: - >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix = False) + >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix = True) >>> format_eng(0) ' 0' >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix = True ) From 9543b9071a1f3dcffd2e2341897db7307f02d59d Mon Sep 17 00:00:00 2001 From: Krishna Chivukula <63070026+KrishnaSai2020@users.noreply.github.com> Date: Tue, 27 Jul 2021 15:20:31 +0100 Subject: [PATCH 15/20] Update format.py --- 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 ba7f8674793d6..d4faab438e12c 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1955,8 +1955,8 @@ def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False): def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter - representing the power of 10 of the original number. Some examples: - >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix = True) + representing the power of 1000 of the original number. Some examples: + >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix=True) >>> format_eng(0) ' 0' >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix = True ) From 5b1d96fe5afcbc56e9288066e9813c306d943933 Mon Sep 17 00:00:00 2001 From: Krishna Chivukula <63070026+KrishnaSai2020@users.noreply.github.com> Date: Tue, 27 Jul 2021 15:21:14 +0100 Subject: [PATCH 16/20] Update format.py --- pandas/io/formats/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index d4faab438e12c..d2a428ac50c22 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1960,7 +1960,7 @@ def __call__(self, num: int | float) -> str: >>> format_eng(0) ' 0' >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix = True ) - >>> format_eng(1000000) + >>> format_eng(1_000_000) ' 1.0M' >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix = False) >>> format_eng("-1e-6") From 98cab71f0581c7babff720c1aee2f6f71cb3bf32 Mon Sep 17 00:00:00 2001 From: Krishna Chivukula <63070026+KrishnaSai2020@users.noreply.github.com> Date: Tue, 27 Jul 2021 15:22:24 +0100 Subject: [PATCH 17/20] Update format.py formatting for pep8 --- 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 d2a428ac50c22..08de6c083c286 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1959,10 +1959,10 @@ def __call__(self, num: int | float) -> str: >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix=True) >>> format_eng(0) ' 0' - >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix = True ) + >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix=True ) >>> format_eng(1_000_000) ' 1.0M' - >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix = False) + >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix=False) >>> format_eng("-1e-6") '-1.00E-06' From e79d33ccb37c482f3dcb911ddf79b48f45bda849 Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 15:50:07 +0100 Subject: [PATCH 18/20] . --- pandas/io/formats/format.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index edf0167c5510c..41a1270413bdb 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1955,19 +1955,23 @@ def __init__(self, accuracy: int | None = None, use_eng_prefix: bool = False): def __call__(self, num: int | float) -> str: """ Formats a number in engineering notation, appending a letter - representing the power of 10 of the original number. Some examples: - >>> format_eng = EngFormatter(0, False) + representing the power of 1000 of the original number. Some examples: + >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix=True) >>> format_eng(0) ' 0' - >>> format_eng = EngFormatter(1, True ) - >>> format_eng(1000000) - + >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix=True ) + >>> format_eng(1_000_000) ' 1.0M' - >>> format_eng = EngFormatter(2, False) + >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix=False) >>> format_eng("-1e-6") - '-1.00E-06' + @param num: the value to represent + @type num: either a numeric value or a string that can be converted to + a numeric value (as per decimal.Decimal constructor) + + @return: engineering formatted string + @param num: the value to represent @type num: either a numeric value or a string that can be converted to a numeric value (as per decimal.Decimal constructor) From 96087825c8752e47102b363b131b3459499c8d9e Mon Sep 17 00:00:00 2001 From: KrishnaSai2020 Date: Tue, 27 Jul 2021 16:33:20 +0100 Subject: [PATCH 19/20] made requested changes --- ci/code_checks.sh | 1 + pandas/io/formats/format.py | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 51119773a4398..88e9b771df9fe 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -122,6 +122,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pandas/io/sas/ \ pandas/io/sql.py \ pandas/tseries/ \ + pandas/io/formats/style_render.py \ pandas/io/formats/format.py RET=$(($RET + $?)) ; echo $MSG "DONE" diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 41a1270413bdb..3fd3d84f90161 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1959,19 +1959,13 @@ def __call__(self, num: int | float) -> str: >>> format_eng = EngFormatter(accuracy=0, use_eng_prefix=True) >>> format_eng(0) ' 0' - >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix=True ) + >>> format_eng = EngFormatter(accuracy=1, use_eng_prefix=True) >>> format_eng(1_000_000) ' 1.0M' >>> format_eng = EngFormatter(accuracy=2, use_eng_prefix=False) >>> format_eng("-1e-6") '-1.00E-06' - @param num: the value to represent - @type num: either a numeric value or a string that can be converted to - a numeric value (as per decimal.Decimal constructor) - - @return: engineering formatted string - @param num: the value to represent @type num: either a numeric value or a string that can be converted to a numeric value (as per decimal.Decimal constructor) From e898934908e0f4635c553b35046f200466ef6a69 Mon Sep 17 00:00:00 2001 From: Krishna Chivukula <63070026+KrishnaSai2020@users.noreply.github.com> Date: Thu, 29 Jul 2021 17:10:10 +0100 Subject: [PATCH 20/20] Update code_checks.sh --- ci/code_checks.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 866d0c260c6e9..f481ecf7a97ed 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -121,7 +121,6 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pandas/io/parsers/ \ pandas/io/sas/ \ pandas/io/sql.py \ - pandas/io/formats/style_render.py \ pandas/io/formats/format.py \ pandas/tseries/ RET=$(($RET + $?)) ; echo $MSG "DONE"