From def4005f8e429fae36a9894c3130c8d1b0aacd62 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Fri, 12 Jul 2019 17:06:31 -0400 Subject: [PATCH 01/15] Created a new validation function (is_pos_int) to allow options to be set up so that they can be either a None type or a positive int. Updated the option creation code for display options that failed when set to negative numbers. --- pandas/_config/config.py | 29 +++++++++++++++++++++++++++++ pandas/core/config_init.py | 17 ++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 61e926035c3f2..0d8e7590f8612 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -787,6 +787,7 @@ def is_instance_factory(_type): ValueError if x is not an instance of `_type` """ + if isinstance(_type, (tuple, list)): _type = tuple(_type) type_repr = "|".join(map(str, _type)) @@ -820,6 +821,34 @@ def inner(x): return inner +def is_pos_int(): + """ + Creates a function for validating that an option value is either a positive + integer or a None type + + Returns + ------- + validator - a function of a single argument x , which raises + ValueError if type(x) is not equal to `_type` or if x is not + positive in the case of a int type. + + """ + + _type = (type(None), int) + type_repr = "|".join(map(str, _type)) + + def inner(x): + if not isinstance(x, _type): + msg = "Value must be an instance of {type_repr}" + raise ValueError(msg.format(type_repr=type_repr)) + if type(x) == int: + if x < 0: + msg = "int values must be positive for this option" + raise ValueError(msg) + + return inner + + # common type validators, for convenience # usage: register_option(... , validator = is_int) is_int = is_type_factory(int) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index be6086dd360f2..55e81d658ed18 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -19,6 +19,7 @@ is_int, is_one_of_factory, is_text, + is_pos_int, ) # compute @@ -319,7 +320,7 @@ def is_terminal(): with cf.config_prefix("display"): - cf.register_option("precision", 6, pc_precision_doc, validator=is_int) + cf.register_option("precision", 6, pc_precision_doc, validator=is_pos_int()) cf.register_option( "float_format", None, @@ -333,12 +334,7 @@ def is_terminal(): pc_max_info_rows_doc, validator=is_instance_factory((int, type(None))), ) - cf.register_option( - "max_rows", - 60, - pc_max_rows_doc, - validator=is_instance_factory([type(None), int]), - ) + cf.register_option("max_rows", 60, pc_max_rows_doc, validator=is_pos_int()) cf.register_option( "min_rows", 10, @@ -351,12 +347,7 @@ def is_terminal(): max_cols = 0 # automatically determine optimal number of columns else: max_cols = 20 # cannot determine optimal number of columns - cf.register_option( - "max_columns", - max_cols, - pc_max_cols_doc, - validator=is_instance_factory([type(None), int]), - ) + cf.register_option("max_columns", max_cols, pc_max_cols_doc, validator=is_pos_int()) cf.register_option( "large_repr", "truncate", From e50961d520c77d77beb4241aec21b623e2416f0c Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Sat, 13 Jul 2019 13:58:50 -0400 Subject: [PATCH 02/15] Added positive and negative tests for is_pos_int in test_validation. --- pandas/tests/config/test_config.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/tests/config/test_config.py b/pandas/tests/config/test_config.py index 3f12d1d7a292d..221c6e1613fc6 100644 --- a/pandas/tests/config/test_config.py +++ b/pandas/tests/config/test_config.py @@ -208,13 +208,16 @@ def test_set_option_multiple(self): def test_validation(self): self.cf.register_option("a", 1, "doc", validator=self.cf.is_int) + self.cf.register_option("d", 1, "doc", validator=self.cf.is_pos_int()) self.cf.register_option("b.c", "hullo", "doc2", validator=self.cf.is_text) + msg = "Value must have type ''" with pytest.raises(ValueError, match=msg): self.cf.register_option("a.b.c.d2", "NO", "doc", validator=self.cf.is_int) self.cf.set_option("a", 2) # int is_int self.cf.set_option("b.c", "wurld") # str is_str + self.cf.set_option("d", 2) # None not is_int with pytest.raises(ValueError, match=msg): @@ -222,6 +225,18 @@ def test_validation(self): with pytest.raises(ValueError, match=msg): self.cf.set_option("a", "ab") + msg = r"Value must be an instance of \|" + with pytest.raises(ValueError, match=msg): + self.cf.register_option( + "a.b.c.d3", "NO", "doc", validator=self.cf.is_pos_int() + ) + + msg = "int values must be positive for this option" + with pytest.raises(ValueError, match=msg): + self.cf.register_option( + "a.b.c.d3", -2, "doc", validator=self.cf.is_pos_int() + ) + msg = r"Value must be an instance of \|" with pytest.raises(ValueError, match=msg): self.cf.set_option("b.c", 1) From 32e8c67e173816d9b15b3d443285a2674ab39129 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Sat, 13 Jul 2019 14:25:26 -0400 Subject: [PATCH 03/15] Updating whatsnew --- doc/source/whatsnew/v0.25.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 68ecb4c487a1e..ade2b281cc2c0 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1188,6 +1188,7 @@ Other - Allow :class:`Index` and :class:`RangeIndex` to be passed to numpy ``min`` and ``max`` functions (:issue:`26125`) - Use actual class name in repr of empty objects of a ``Series`` subclass (:issue:`27001`). - Bug in :class:`DataFrame` where passing an object array of timezone-aware `datetime` objects would incorrectly raise ``ValueError`` (:issue:`13287`) +- Added a new option validation function (is_pos_int) to allow only positive integers, and set the display.precision, display.max_rows and display.max_columns options to use it (:issue:`23348`) .. _whatsnew_0.250.contributors: From 9618877f85da02e276613b8cc247bb2805a19e7a Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Sat, 13 Jul 2019 15:25:04 -0400 Subject: [PATCH 04/15] Fixing order as per isort --- pandas/core/config_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 55e81d658ed18..6b956ab6cdf86 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -18,8 +18,8 @@ is_instance_factory, is_int, is_one_of_factory, - is_text, is_pos_int, + is_text, ) # compute From 7a5593ba364c2610442e094c2db47ac9e6cfdbf7 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Mon, 15 Jul 2019 09:44:32 -0400 Subject: [PATCH 05/15] Simplified the is_pos_int function to be used standalone rather than returning an additional function. This also allows it to be used in an identical fasion to is_int, is_text etc. Modified the validation calls to is_pos_int to remove (). Modified the tests using is_pos_int to remove (). Updated whatsnew documentation to be more user focused. --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/_config/config.py | 33 ++++++++++++------------------ pandas/core/config_init.py | 6 +++--- pandas/tests/config/test_config.py | 8 +++----- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index ade2b281cc2c0..d5cedfb24affa 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1188,7 +1188,7 @@ Other - Allow :class:`Index` and :class:`RangeIndex` to be passed to numpy ``min`` and ``max`` functions (:issue:`26125`) - Use actual class name in repr of empty objects of a ``Series`` subclass (:issue:`27001`). - Bug in :class:`DataFrame` where passing an object array of timezone-aware `datetime` objects would incorrectly raise ``ValueError`` (:issue:`13287`) -- Added a new option validation function (is_pos_int) to allow only positive integers, and set the display.precision, display.max_rows and display.max_columns options to use it (:issue:`23348`) +- Trying to set the display.precision, display.max_rows or display.max_columns options to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) .. _whatsnew_0.250.contributors: diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 0d8e7590f8612..0ca82012bcb0c 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -821,32 +821,25 @@ def inner(x): return inner -def is_pos_int(): +def is_pos_int(value): """ - Creates a function for validating that an option value is either a positive - integer or a None type + Raises ValueError if type(x) is not equal to None or int, or if x is not + positive in the case of a int type. - Returns - ------- - validator - a function of a single argument x , which raises - ValueError if type(x) is not equal to `_type` or if x is not - positive in the case of a int type. + Parameters + ---------- + value - the value to be checked """ - _type = (type(None), int) - type_repr = "|".join(map(str, _type)) + if not (value is None or isinstance(value, int)): + msg = "Value must be an instance of |" + raise ValueError(msg) - def inner(x): - if not isinstance(x, _type): - msg = "Value must be an instance of {type_repr}" - raise ValueError(msg.format(type_repr=type_repr)) - if type(x) == int: - if x < 0: - msg = "int values must be positive for this option" - raise ValueError(msg) - - return inner + elif isinstance(value, int): + if value < 0: + msg = "int values must be positive for this option" + raise ValueError(msg) # common type validators, for convenience diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 6b956ab6cdf86..4a36e2858dee5 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -320,7 +320,7 @@ def is_terminal(): with cf.config_prefix("display"): - cf.register_option("precision", 6, pc_precision_doc, validator=is_pos_int()) + cf.register_option("precision", 6, pc_precision_doc, validator=is_pos_int) cf.register_option( "float_format", None, @@ -334,7 +334,7 @@ def is_terminal(): pc_max_info_rows_doc, validator=is_instance_factory((int, type(None))), ) - cf.register_option("max_rows", 60, pc_max_rows_doc, validator=is_pos_int()) + cf.register_option("max_rows", 60, pc_max_rows_doc, validator=is_pos_int) cf.register_option( "min_rows", 10, @@ -347,7 +347,7 @@ def is_terminal(): max_cols = 0 # automatically determine optimal number of columns else: max_cols = 20 # cannot determine optimal number of columns - cf.register_option("max_columns", max_cols, pc_max_cols_doc, validator=is_pos_int()) + cf.register_option("max_columns", max_cols, pc_max_cols_doc, validator=is_pos_int) cf.register_option( "large_repr", "truncate", diff --git a/pandas/tests/config/test_config.py b/pandas/tests/config/test_config.py index 221c6e1613fc6..2c302d020fd72 100644 --- a/pandas/tests/config/test_config.py +++ b/pandas/tests/config/test_config.py @@ -208,7 +208,7 @@ def test_set_option_multiple(self): def test_validation(self): self.cf.register_option("a", 1, "doc", validator=self.cf.is_int) - self.cf.register_option("d", 1, "doc", validator=self.cf.is_pos_int()) + self.cf.register_option("d", 1, "doc", validator=self.cf.is_pos_int) self.cf.register_option("b.c", "hullo", "doc2", validator=self.cf.is_text) msg = "Value must have type ''" @@ -228,14 +228,12 @@ def test_validation(self): msg = r"Value must be an instance of \|" with pytest.raises(ValueError, match=msg): self.cf.register_option( - "a.b.c.d3", "NO", "doc", validator=self.cf.is_pos_int() + "a.b.c.d3", "NO", "doc", validator=self.cf.is_pos_int ) msg = "int values must be positive for this option" with pytest.raises(ValueError, match=msg): - self.cf.register_option( - "a.b.c.d3", -2, "doc", validator=self.cf.is_pos_int() - ) + self.cf.register_option("a.b.c.d3", -2, "doc", validator=self.cf.is_pos_int) msg = r"Value must be an instance of \|" with pytest.raises(ValueError, match=msg): From d6fa25848f967b8f7adc0bd5d3164c4576cf3f2b Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Tue, 16 Jul 2019 08:53:59 -0400 Subject: [PATCH 06/15] Updated is_pos_int docstring with Returns and Raises --- pandas/_config/config.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 0ca82012bcb0c..3e56035dcd637 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -823,13 +823,21 @@ def inner(x): def is_pos_int(value): """ - Raises ValueError if type(x) is not equal to None or int, or if x is not - positive in the case of a int type. - + Verifies that value is None or a positive int Parameters ---------- value - the value to be checked + + Returns + ---------- + None + + Raises + ---------- + ValueError if value is not equal to None or int, or if value is not + positive in the case of a int type. + """ if not (value is None or isinstance(value, int)): From eb098137f85b6219b21a6f9902c0775a31131736 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Thu, 18 Jul 2019 17:28:21 -0400 Subject: [PATCH 07/15] Clarifying documentation --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index d5cedfb24affa..1af27b787df69 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1188,7 +1188,7 @@ Other - Allow :class:`Index` and :class:`RangeIndex` to be passed to numpy ``min`` and ``max`` functions (:issue:`26125`) - Use actual class name in repr of empty objects of a ``Series`` subclass (:issue:`27001`). - Bug in :class:`DataFrame` where passing an object array of timezone-aware `datetime` objects would incorrectly raise ``ValueError`` (:issue:`13287`) -- Trying to set the display.precision, display.max_rows or display.max_columns options to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) +- Trying to set the display.precision, display.max_rows or display.max_columns using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) .. _whatsnew_0.250.contributors: From 21bf599a88a8b62b049636bdcb3a67ce9f04bbd3 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Tue, 23 Jul 2019 21:44:33 -0400 Subject: [PATCH 08/15] Removed Returns section from docstring. Set dash length to be the same as the Raises keyword in docstring. --- pandas/_config/config.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 3e56035dcd637..6a03f7bc257b8 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -829,12 +829,8 @@ def is_pos_int(value): ---------- value - the value to be checked - Returns - ---------- - None - Raises - ---------- + ------ ValueError if value is not equal to None or int, or if value is not positive in the case of a int type. From ea09cc2dcce464d39c67d65b03d75f095aaa8861 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Tue, 23 Jul 2019 22:35:22 -0400 Subject: [PATCH 09/15] Moved whatsnew documentation from v25 to v26 --- doc/source/whatsnew/v0.25.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 88c50bfe6dedf..42e756635e739 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -1261,7 +1261,6 @@ Other - Allow :class:`Index` and :class:`RangeIndex` to be passed to numpy ``min`` and ``max`` functions (:issue:`26125`) - Use actual class name in repr of empty objects of a ``Series`` subclass (:issue:`27001`). - Bug in :class:`DataFrame` where passing an object array of timezone-aware `datetime` objects would incorrectly raise ``ValueError`` (:issue:`13287`) -- Trying to set the display.precision, display.max_rows or display.max_columns using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) .. _whatsnew_0.250.contributors: From 6c2ff432ef077e19b6f983d228954eccc7bf2599 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Tue, 23 Jul 2019 22:39:46 -0400 Subject: [PATCH 10/15] Added documentation to Other section --- doc/source/whatsnew/v0.26.0.rst | 201 ++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 doc/source/whatsnew/v0.26.0.rst diff --git a/doc/source/whatsnew/v0.26.0.rst b/doc/source/whatsnew/v0.26.0.rst new file mode 100644 index 0000000000000..727f833d7538a --- /dev/null +++ b/doc/source/whatsnew/v0.26.0.rst @@ -0,0 +1,201 @@ +.. _whatsnew_0260: + +What's new in 0.26.0 (??) +------------------------ + +.. warning:: + + Starting with the 0.25.x series of releases, pandas only supports Python 3.5.3 and higher. + See :ref:`install.dropping-27` for more details. + +.. warning:: + + The minimum supported Python version will be bumped to 3.6 in a future release. + +{{ header }} + +These are the changes in pandas 0.26.0. See :ref:`release` for a full changelog +including other versions of pandas. + + +Enhancements +~~~~~~~~~~~~ + +.. _whatsnew_0260.enhancements.other: + +- +- + +Other enhancements +^^^^^^^^^^^^^^^^^^ + +.. _whatsnew_0260.api_breaking: + +- +- + +Backwards incompatible API changes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. _whatsnew_0260.api.other: + +- +- + +Other API changes +^^^^^^^^^^^^^^^^^ + +- +- + +.. _whatsnew_0260.deprecations: + +Deprecations +~~~~~~~~~~~~ + +- +- + +.. _whatsnew_0260.prior_deprecations: + +Removal of prior version deprecations/changes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- +- + +.. _whatsnew_0260.performance: + +Performance improvements +~~~~~~~~~~~~~~~~~~~~~~~~ + +- +- + +.. _whatsnew_0260.bug_fixes: + +Bug fixes +~~~~~~~~~ + + +Categorical +^^^^^^^^^^^ + +- +- + + +Datetimelike +^^^^^^^^^^^^ + +- +- + + +Timedelta +^^^^^^^^^ + +- +- + +Timezones +^^^^^^^^^ + +- +- + + +Numeric +^^^^^^^ + +- +- + +Conversion +^^^^^^^^^^ + +- +- + +Strings +^^^^^^^ + +- +- + + +Interval +^^^^^^^^ + +- +- + +Indexing +^^^^^^^^ + +- +- + +Missing +^^^^^^^ + +- +- + +MultiIndex +^^^^^^^^^^ + +- +- + +I/O +^^^ + +- +- + +Plotting +^^^^^^^^ + +- +- + +Groupby/resample/rolling +^^^^^^^^^^^^^^^^^^^^^^^^ + +- +- + +Reshaping +^^^^^^^^^ + +- +- + +Sparse +^^^^^^ + +- +- + + +Build Changes +^^^^^^^^^^^^^ + + +ExtensionArray +^^^^^^^^^^^^^^ + +- +- + + +Other +^^^^^ +- Trying to set the display.precision, display.max_rows or display.max_columns using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) + + +.. _whatsnew_0260.contributors: + +Contributors +~~~~~~~~~~~~ From d18a01a6b7d84f55990e0cb1e801f222a1c28a58 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Sat, 27 Jul 2019 11:30:30 -0400 Subject: [PATCH 11/15] Moving comments to v1.0.0 file --- doc/source/whatsnew/v0.26.0.rst | 201 -------------------------------- doc/source/whatsnew/v1.0.0.rst | 6 + 2 files changed, 6 insertions(+), 201 deletions(-) delete mode 100644 doc/source/whatsnew/v0.26.0.rst diff --git a/doc/source/whatsnew/v0.26.0.rst b/doc/source/whatsnew/v0.26.0.rst deleted file mode 100644 index 727f833d7538a..0000000000000 --- a/doc/source/whatsnew/v0.26.0.rst +++ /dev/null @@ -1,201 +0,0 @@ -.. _whatsnew_0260: - -What's new in 0.26.0 (??) ------------------------- - -.. warning:: - - Starting with the 0.25.x series of releases, pandas only supports Python 3.5.3 and higher. - See :ref:`install.dropping-27` for more details. - -.. warning:: - - The minimum supported Python version will be bumped to 3.6 in a future release. - -{{ header }} - -These are the changes in pandas 0.26.0. See :ref:`release` for a full changelog -including other versions of pandas. - - -Enhancements -~~~~~~~~~~~~ - -.. _whatsnew_0260.enhancements.other: - -- -- - -Other enhancements -^^^^^^^^^^^^^^^^^^ - -.. _whatsnew_0260.api_breaking: - -- -- - -Backwards incompatible API changes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. _whatsnew_0260.api.other: - -- -- - -Other API changes -^^^^^^^^^^^^^^^^^ - -- -- - -.. _whatsnew_0260.deprecations: - -Deprecations -~~~~~~~~~~~~ - -- -- - -.. _whatsnew_0260.prior_deprecations: - -Removal of prior version deprecations/changes -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -- -- - -.. _whatsnew_0260.performance: - -Performance improvements -~~~~~~~~~~~~~~~~~~~~~~~~ - -- -- - -.. _whatsnew_0260.bug_fixes: - -Bug fixes -~~~~~~~~~ - - -Categorical -^^^^^^^^^^^ - -- -- - - -Datetimelike -^^^^^^^^^^^^ - -- -- - - -Timedelta -^^^^^^^^^ - -- -- - -Timezones -^^^^^^^^^ - -- -- - - -Numeric -^^^^^^^ - -- -- - -Conversion -^^^^^^^^^^ - -- -- - -Strings -^^^^^^^ - -- -- - - -Interval -^^^^^^^^ - -- -- - -Indexing -^^^^^^^^ - -- -- - -Missing -^^^^^^^ - -- -- - -MultiIndex -^^^^^^^^^^ - -- -- - -I/O -^^^ - -- -- - -Plotting -^^^^^^^^ - -- -- - -Groupby/resample/rolling -^^^^^^^^^^^^^^^^^^^^^^^^ - -- -- - -Reshaping -^^^^^^^^^ - -- -- - -Sparse -^^^^^^ - -- -- - - -Build Changes -^^^^^^^^^^^^^ - - -ExtensionArray -^^^^^^^^^^^^^^ - -- -- - - -Other -^^^^^ -- Trying to set the display.precision, display.max_rows or display.max_columns using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) - - -.. _whatsnew_0260.contributors: - -Contributors -~~~~~~~~~~~~ diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index cc4bab8b9a923..caa249c845957 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -190,6 +190,12 @@ ExtensionArray - - + +Other +^^^^^ +- Trying to set the display.precision, display.max_rows or display.max_columns using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) + + .. _whatsnew_1000.contributors: Contributors From 4e76640834905396ec84fc120682c2aee03ae60e Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Mon, 29 Jul 2019 19:16:03 -0400 Subject: [PATCH 12/15] Added double ticks around display parameters in whatsnew. Simplified is_pos_int function and updated tests accordingly Rewrote is_pos_int docstring to conform to standards --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/_config/config.py | 22 +++++++++++----------- pandas/tests/config/test_config.py | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index caa249c845957..fde9a0b9641c2 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -193,7 +193,7 @@ ExtensionArray Other ^^^^^ -- Trying to set the display.precision, display.max_rows or display.max_columns using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) +- Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) .. _whatsnew_1000.contributors: diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 6a03f7bc257b8..cf22fbcba9033 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -823,27 +823,27 @@ def inner(x): def is_pos_int(value): """ - Verifies that value is None or a positive int + Verify that value is None or a positive int. Parameters ---------- - value - the value to be checked + value : None or int + The `value` to be checked. Raises ------ - ValueError if value is not equal to None or int, or if value is not - positive in the case of a int type. - + ValueError if the value is not equal to a positive integer, 0 or None. """ - if not (value is None or isinstance(value, int)): - msg = "Value must be an instance of |" - raise ValueError(msg) + if value is None: + return elif isinstance(value, int): - if value < 0: - msg = "int values must be positive for this option" - raise ValueError(msg) + if value >= 0: + return + + msg = "Value must be a positive integer, 0 or None" + raise ValueError(msg) # common type validators, for convenience diff --git a/pandas/tests/config/test_config.py b/pandas/tests/config/test_config.py index 2c302d020fd72..a5953af898e83 100644 --- a/pandas/tests/config/test_config.py +++ b/pandas/tests/config/test_config.py @@ -225,13 +225,13 @@ def test_validation(self): with pytest.raises(ValueError, match=msg): self.cf.set_option("a", "ab") - msg = r"Value must be an instance of \|" + msg = "Value must be a positive integer or None" with pytest.raises(ValueError, match=msg): self.cf.register_option( "a.b.c.d3", "NO", "doc", validator=self.cf.is_pos_int ) - msg = "int values must be positive for this option" + msg = "Value must be a positive integer or None" with pytest.raises(ValueError, match=msg): self.cf.register_option("a.b.c.d3", -2, "doc", validator=self.cf.is_pos_int) From 2d783ef452a8c3d190067b3c6e8d918f391a4b13 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Tue, 30 Jul 2019 09:15:17 -0400 Subject: [PATCH 13/15] Corrected is_pos_int ValueError message in test suite --- pandas/tests/config/test_config.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/config/test_config.py b/pandas/tests/config/test_config.py index a5953af898e83..3b6a5d19942a5 100644 --- a/pandas/tests/config/test_config.py +++ b/pandas/tests/config/test_config.py @@ -225,13 +225,11 @@ def test_validation(self): with pytest.raises(ValueError, match=msg): self.cf.set_option("a", "ab") - msg = "Value must be a positive integer or None" + msg = "Value must be a positive integer, 0 or None" with pytest.raises(ValueError, match=msg): self.cf.register_option( "a.b.c.d3", "NO", "doc", validator=self.cf.is_pos_int ) - - msg = "Value must be a positive integer or None" with pytest.raises(ValueError, match=msg): self.cf.register_option("a.b.c.d3", -2, "doc", validator=self.cf.is_pos_int) From 033339fe7eac151a2cf66bfc5b1f3658ce0926a3 Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Sun, 4 Aug 2019 18:40:48 -0400 Subject: [PATCH 14/15] Refactored is_pos_int to is_nonnegative_int and updated whatsnew. --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/_config/config.py | 7 ++++--- pandas/core/config_init.py | 10 ++++++---- pandas/tests/config/test_config.py | 10 ++++++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index fde9a0b9641c2..c0c5cf15fca98 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -193,7 +193,7 @@ ExtensionArray Other ^^^^^ -- Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using set_option to anything but a None or a positive int will raise a ``ValueError`` (:issue:`23348`) +- Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using :meth:`set_option` to anything but a ``None`` or a positive int will raise a ``ValueError`` (:issue:`23348`) .. _whatsnew_1000.contributors: diff --git a/pandas/_config/config.py b/pandas/_config/config.py index d0fa0d4b1a282..890db5b41907e 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -821,7 +821,7 @@ def inner(x): return inner -def is_pos_int(value): +def is_nonnegative_int(value): """ Verify that value is None or a positive int. @@ -832,7 +832,8 @@ def is_pos_int(value): Raises ------ - ValueError if the value is not equal to a positive integer, 0 or None. + ValueError + When the value is not None or is a negative integer """ if value is None: @@ -842,7 +843,7 @@ def is_pos_int(value): if value >= 0: return - msg = "Value must be a positive integer, 0 or None" + msg = "Value must be a nonnegative integer or None" raise ValueError(msg) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 4a36e2858dee5..3256fd2eb0794 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -18,7 +18,7 @@ is_instance_factory, is_int, is_one_of_factory, - is_pos_int, + is_nonnegative_int, is_text, ) @@ -320,7 +320,7 @@ def is_terminal(): with cf.config_prefix("display"): - cf.register_option("precision", 6, pc_precision_doc, validator=is_pos_int) + cf.register_option("precision", 6, pc_precision_doc, validator=is_nonnegative_int) cf.register_option( "float_format", None, @@ -334,7 +334,7 @@ def is_terminal(): pc_max_info_rows_doc, validator=is_instance_factory((int, type(None))), ) - cf.register_option("max_rows", 60, pc_max_rows_doc, validator=is_pos_int) + cf.register_option("max_rows", 60, pc_max_rows_doc, validator=is_nonnegative_int) cf.register_option( "min_rows", 10, @@ -347,7 +347,9 @@ def is_terminal(): max_cols = 0 # automatically determine optimal number of columns else: max_cols = 20 # cannot determine optimal number of columns - cf.register_option("max_columns", max_cols, pc_max_cols_doc, validator=is_pos_int) + cf.register_option( + "max_columns", max_cols, pc_max_cols_doc, validator=is_nonnegative_int + ) cf.register_option( "large_repr", "truncate", diff --git a/pandas/tests/config/test_config.py b/pandas/tests/config/test_config.py index 3b6a5d19942a5..efaeb7b1471ec 100644 --- a/pandas/tests/config/test_config.py +++ b/pandas/tests/config/test_config.py @@ -208,7 +208,7 @@ def test_set_option_multiple(self): def test_validation(self): self.cf.register_option("a", 1, "doc", validator=self.cf.is_int) - self.cf.register_option("d", 1, "doc", validator=self.cf.is_pos_int) + self.cf.register_option("d", 1, "doc", validator=self.cf.is_nonnegative_int) self.cf.register_option("b.c", "hullo", "doc2", validator=self.cf.is_text) msg = "Value must have type ''" @@ -225,13 +225,15 @@ def test_validation(self): with pytest.raises(ValueError, match=msg): self.cf.set_option("a", "ab") - msg = "Value must be a positive integer, 0 or None" + msg = "Value must be a nonnegative integer or None" with pytest.raises(ValueError, match=msg): self.cf.register_option( - "a.b.c.d3", "NO", "doc", validator=self.cf.is_pos_int + "a.b.c.d3", "NO", "doc", validator=self.cf.is_nonnegative_int ) with pytest.raises(ValueError, match=msg): - self.cf.register_option("a.b.c.d3", -2, "doc", validator=self.cf.is_pos_int) + self.cf.register_option( + "a.b.c.d3", -2, "doc", validator=self.cf.is_nonnegative_int + ) msg = r"Value must be an instance of \|" with pytest.raises(ValueError, match=msg): From 1a25d065b3b3af7eae182138b75c210bbe7ce37c Mon Sep 17 00:00:00 2001 From: Adam Klaum Date: Sun, 4 Aug 2019 22:15:19 -0400 Subject: [PATCH 15/15] Fixing import sorting issue --- pandas/core/config_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 3256fd2eb0794..08dce6aca6e6d 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -17,8 +17,8 @@ is_callable, is_instance_factory, is_int, - is_one_of_factory, is_nonnegative_int, + is_one_of_factory, is_text, )