Skip to content

DOC: Adding docstrings to functions #15580 #52774

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

Closed
wants to merge 10 commits into from
60 changes: 60 additions & 0 deletions pandas/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,70 @@


def using_copy_on_write() -> bool:
"""
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
----------
None

Comment on lines +42 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used elsewhere in the docs? if not, I think we can just leave the parameters section out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

Returns
-------
bool
'True' if copy-on-write mode is enabled and the data manager
is set to "block", otherwise 'False'.

Example
-------
>>> 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
Comment on lines +54 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a couple of issues here:

  1. most of these options aren't relevant to this example
  2. the options will stay set after the doctest for this function has finished (there have been issues due to this in the past)

How about we just put something like

>>> pd.set_option('mode.copy', True)
>>> using_copy_on_write()
True
>>> pd.unset_option('mode.copy')
>>> using_copy_on_write()
False

(I haven't tried running this, so the syntax might not be correct)

"""
_mode_options = _global_config["mode"]
return _mode_options["copy_on_write"] and _mode_options["data_manager"] == "block"


def using_nullable_dtypes() -> bool:
"""
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
----------
None

Returns
-------
bool
'True' if pandas is using nullable data types, otherwise 'False'.

Example
-------
>>> pd.set_option('mode.use_inf_as_na', True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

>>> pd.set_option('mode.use_nullable_dtypes', True)
>>> using_nullable_dtypes()
True
>>> 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does is_extension_type initialise the configuration settings? I don't remember having come across this, could you please let me know where you found it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, it doesn't initialize or make changes for that matter on the Settings.
After some reasearch, pandas.api.extensions.initialize() is more appropriate in this case. Do you recommend I edit this not or is the note really necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's pandas.api.extensions.initialize? where did you get this from?

"""
_mode_options = _global_config["mode"]
return _mode_options["nullable_dtypes"]