From 3218cfbfbd39abdfc8fe6ad98267a3e4872a25c6 Mon Sep 17 00:00:00 2001 From: Wendy Gonzales Date: Mon, 17 Apr 2023 18:58:22 -0500 Subject: [PATCH 1/8] Add docstring to using_copy_on_write function --- pandas/_config/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/_config/__init__.py b/pandas/_config/__init__.py index 73ed99c3a4640..3ae580a2743c3 100644 --- a/pandas/_config/__init__.py +++ b/pandas/_config/__init__.py @@ -31,6 +31,16 @@ def using_copy_on_write() -> bool: + ''' + This function examines the global pandas configuration + settings to determine if copy-on-write mode is being used. + Copy-on-write is a memory-saving technique that avoids copying + data until it is actually modified, which can be particularly + useful when working with large datasets. + If copy-on-write is enabled and the data manager is set to "block", the function returns True, + otherwise it returns False. + + ''' _mode_options = _global_config["mode"] return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block" From 17061d9a20fcdc5126ca27a5e7f3bfc057750c62 Mon Sep 17 00:00:00 2001 From: Wendy Gonzales Date: Mon, 17 Apr 2023 19:01:37 -0500 Subject: [PATCH 2/8] Add docstring to using_nullable_dtypes function --- pandas/_config/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/_config/__init__.py b/pandas/_config/__init__.py index 3ae580a2743c3..102171f86eb8c 100644 --- a/pandas/_config/__init__.py +++ b/pandas/_config/__init__.py @@ -46,5 +46,13 @@ def using_copy_on_write() -> bool: def using_nullable_dtypes() -> bool: + """ + This function examines the global pandas configuration settings to determine if nullable data types are being used. + If pandas is using nullable data types, the function will return True. Otherwise, it will return False. + + Note: This function assumes that the global pandas configuration settings have already been initialized. + If you are not sure whether the settings have been initialized, you can call the `pandas.api.types.is_extension_type()` function to force initialization. + + """ _mode_options = _global_config["mode"] return _mode_options["nullable_dtypes"] From bf21068a5f02f4109f3a0a58bed49c5584a86208 Mon Sep 17 00:00:00 2001 From: Wendy Gonzales Date: Tue, 18 Apr 2023 21:02:41 -0500 Subject: [PATCH 3/8] Add ex. to using_copy_on_write docstring --- pandas/_config/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pandas/_config/__init__.py b/pandas/_config/__init__.py index 102171f86eb8c..ef8c046f0ee8f 100644 --- a/pandas/_config/__init__.py +++ b/pandas/_config/__init__.py @@ -37,9 +37,19 @@ def using_copy_on_write() -> bool: Copy-on-write is a memory-saving technique that avoids copying data until it is actually modified, which can be particularly useful when working with large datasets. - If copy-on-write is enabled and the data manager is set to "block", the function returns True, - otherwise it returns False. + Returns: + Bool: True if copy-on-write mode is enabled and the data manager is set to "block", + False otherwise. + Example: + >>> import pandas as pd + >>> pd.set_option('mode.chained_assignment', 'raise') + >>> pd.set_option('mode.copy', True) + >>> pd.set_option('mode.use_inf_as_na', True) + >>> pd.set_option('compute.use_bottleneck', False) + >>> pd.set_option('compute.use_numexpr', False) + >>> using_copy_on_write() + True ''' _mode_options = _global_config["mode"] return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block" From 149cb8052a87ad8741ab9d2abf7c1cf2b7b02a8c Mon Sep 17 00:00:00 2001 From: Wendy Gonzales Date: Tue, 18 Apr 2023 21:08:23 -0500 Subject: [PATCH 4/8] Ad ex. to using_nullable_dtypes docstring --- pandas/_config/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/_config/__init__.py b/pandas/_config/__init__.py index ef8c046f0ee8f..fd3f8238250f9 100644 --- a/pandas/_config/__init__.py +++ b/pandas/_config/__init__.py @@ -63,6 +63,15 @@ def using_nullable_dtypes() -> bool: Note: This function assumes that the global pandas configuration settings have already been initialized. If you are not sure whether the settings have been initialized, you can call the `pandas.api.types.is_extension_type()` function to force initialization. + Examples: + >>> import pandas as pd + >>> pd.set_option('mode.use_inf_as_na', True) + >>> pd.set_option('mode.use_nullable_dtypes', True) + >>> using_nullable_dtypes() + True + >>> pd.set_option('mode.use_nullable_dtypes', False) + >>> using_nullable_dtypes() + False """ _mode_options = _global_config["mode"] return _mode_options["nullable_dtypes"] From bee8c9ec07b2a75e6ba9f30f8e7983d1c33ebf02 Mon Sep 17 00:00:00 2001 From: Wendy Gonzales Date: Fri, 21 Apr 2023 20:16:07 -0500 Subject: [PATCH 5/8] Fixed pre-commit failures --- pandas/.pre-commit-config.yaml | 13 ++++++++ pandas/_config/__init__.py | 59 ++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 pandas/.pre-commit-config.yaml diff --git a/pandas/.pre-commit-config.yaml b/pandas/.pre-commit-config.yaml new file mode 100644 index 0000000000000..2ebdd861c425f --- /dev/null +++ b/pandas/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.9.2 + hooks: + - id: codespell + - id: check-added-large-files + - id: flake8 + - id: pylint + - id: pytest +- repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black diff --git a/pandas/_config/__init__.py b/pandas/_config/__init__.py index fd3f8238250f9..f92025126548a 100644 --- a/pandas/_config/__init__.py +++ b/pandas/_config/__init__.py @@ -31,17 +31,26 @@ def using_copy_on_write() -> bool: - ''' - This function examines the global pandas configuration - settings to determine if copy-on-write mode is being used. - Copy-on-write is a memory-saving technique that avoids copying - data until it is actually modified, which can be particularly - useful when working with large datasets. - Returns: - Bool: True if copy-on-write mode is enabled and the data manager is set to "block", - False otherwise. + """ + This function examines the global pandas configuration settings to + determine if copy-on-write mode is being used. Copy-on-write is a + memory-saving technique that avoids copying data until it is actually + modified, which can be particularly useful when working with large + datasets. + + Parameters + ---------- + No arguments - Example: + Returns + ---------- + Bool: + True if copy-on-write mode is enabled and the data manager + is set to "block", + False otherwise. + + Example + ---------- >>> import pandas as pd >>> pd.set_option('mode.chained_assignment', 'raise') >>> pd.set_option('mode.copy', True) @@ -49,21 +58,29 @@ def using_copy_on_write() -> bool: >>> pd.set_option('compute.use_bottleneck', False) >>> pd.set_option('compute.use_numexpr', False) >>> using_copy_on_write() - True - ''' + True + """ _mode_options = _global_config["mode"] return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block" def using_nullable_dtypes() -> bool: """ - This function examines the global pandas configuration settings to determine if nullable data types are being used. - If pandas is using nullable data types, the function will return True. Otherwise, it will return False. + This function examines the global pandas configuration settings to + determine if nullable data types are being used. + + Parameters + ---------- + No arguments - Note: This function assumes that the global pandas configuration settings have already been initialized. - If you are not sure whether the settings have been initialized, you can call the `pandas.api.types.is_extension_type()` function to force initialization. + Returns + ---------- + Bool: + True if pandas is using nullable data types. + False otherwise - Examples: + Example + ---------- >>> import pandas as pd >>> pd.set_option('mode.use_inf_as_na', True) >>> pd.set_option('mode.use_nullable_dtypes', True) @@ -72,6 +89,14 @@ def using_nullable_dtypes() -> bool: >>> pd.set_option('mode.use_nullable_dtypes', False) >>> using_nullable_dtypes() False + + Notes + ---------- + This function assumes that the global pandas configuration settings have + already been initialized. If you are not sure whether the settings + have been initialized, you can call the + pandas.api.types.is_extension_type() function to force initialization. + """ _mode_options = _global_config["mode"] return _mode_options["nullable_dtypes"] From fa883f840dcbf95562e8b3ac71e8439a6344ee33 Mon Sep 17 00:00:00 2001 From: wcgonzal Date: Fri, 21 Apr 2023 21:33:49 -0500 Subject: [PATCH 6/8] Delete .pre-commit-config.yaml Accidentally added an unnecessary file to my pull request. --- pandas/.pre-commit-config.yaml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 pandas/.pre-commit-config.yaml diff --git a/pandas/.pre-commit-config.yaml b/pandas/.pre-commit-config.yaml deleted file mode 100644 index 2ebdd861c425f..0000000000000 --- a/pandas/.pre-commit-config.yaml +++ /dev/null @@ -1,13 +0,0 @@ -repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.9.2 - hooks: - - id: codespell - - id: check-added-large-files - - id: flake8 - - id: pylint - - id: pytest -- repo: https://github.com/psf/black - rev: 23.1.0 - hooks: - - id: black From bc09ea0b2eb270a9b130694cd4a973fd43517c7b Mon Sep 17 00:00:00 2001 From: Wendy Gonzales Date: Wed, 26 Apr 2023 22:08:27 -0500 Subject: [PATCH 7/8] Updated docstring to fix pre-commit failures --- pandas/_config/__init__.py | 50 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/pandas/_config/__init__.py b/pandas/_config/__init__.py index f92025126548a..8d301fa0b0a74 100644 --- a/pandas/_config/__init__.py +++ b/pandas/_config/__init__.py @@ -32,26 +32,25 @@ def using_copy_on_write() -> bool: """ - This function examines the global pandas configuration settings to - determine if copy-on-write mode is being used. Copy-on-write is a - memory-saving technique that avoids copying data until it is actually - modified, which can be particularly useful when working with large - datasets. + Determine if copy-on-write mode is being used. + + This function examines the global pandas configuration settings. + Copy-on-write is a memory-saving technique that avoids copying data + until it is actually modified, which can be particularly useful when + working with large datasets. Parameters ---------- - No arguments + None Returns - ---------- - Bool: - True if copy-on-write mode is enabled and the data manager - is set to "block", - False otherwise. + ------- + bool + 'True' if copy-on-write mode is enabled and the data manager + is set to "block", otherwise 'False'. Example - ---------- - >>> import pandas as pd + ------- >>> pd.set_option('mode.chained_assignment', 'raise') >>> pd.set_option('mode.copy', True) >>> pd.set_option('mode.use_inf_as_na', True) @@ -61,27 +60,27 @@ def using_copy_on_write() -> bool: True """ _mode_options = _global_config["mode"] - return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block" + return _mode_options["3_on_write"] and _mode_options["data_manager"] == "block" def using_nullable_dtypes() -> bool: """ - This function examines the global pandas configuration settings to - determine if nullable data types are being used. + Determine if nullable data types are being used. + + This function reads the `mode` configuration option from the global + configuration object and indicate whether nullable data types are allowed. Parameters ---------- - No arguments + None Returns - ---------- - Bool: - True if pandas is using nullable data types. - False otherwise + ------- + bool + 'True' if pandas is using nullable data types, otherwise 'False'. Example - ---------- - >>> import pandas as pd + ------- >>> pd.set_option('mode.use_inf_as_na', True) >>> pd.set_option('mode.use_nullable_dtypes', True) >>> using_nullable_dtypes() @@ -91,12 +90,11 @@ def using_nullable_dtypes() -> bool: False Notes - ---------- + ----- This function assumes that the global pandas configuration settings have already been initialized. If you are not sure whether the settings have been initialized, you can call the - pandas.api.types.is_extension_type() function to force initialization. - + pandas.api.types.is_extension_type() function to force initialization. """ _mode_options = _global_config["mode"] return _mode_options["nullable_dtypes"] From 03dce2b5eecfad401ffac7154c08da07cf76fd9a Mon Sep 17 00:00:00 2001 From: Wendy Gonzales Date: Wed, 26 Apr 2023 22:58:22 -0500 Subject: [PATCH 8/8] Corrected 3_on_write to copy_on_write --- pandas/_config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_config/__init__.py b/pandas/_config/__init__.py index 8d301fa0b0a74..a034daf1c5c23 100644 --- a/pandas/_config/__init__.py +++ b/pandas/_config/__init__.py @@ -60,7 +60,7 @@ def using_copy_on_write() -> bool: True """ _mode_options = _global_config["mode"] - return _mode_options["3_on_write"] and _mode_options["data_manager"] == "block" + return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block" def using_nullable_dtypes() -> bool: