Skip to content

DOC: Add docstring for asarray_tuplesafe in common.py #62079

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = ...) -> ArrayLik


def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = None) -> ArrayLike:
"""
Convert input values to a NumPy array or ExtensionArray,
preserving tuples as single elements.

Parameters
----------
values : iterable or array-like
The data to be converted. Tuples preserved as single elements.
dtype : numpy.dtype or None, default None
Data type for the result. If None, the dtype is inferred.

Returns
-------
ndarray or ExtensionArray
The converted array or extension array.

Notes
-----
For object dtype lists, uses
`construct_1d_object_array_from_listlike` to preserve structure.
"""
if not (isinstance(values, (list, tuple)) or hasattr(values, "__array__")):
values = list(values)
elif isinstance(values, ABCIndex):
Expand Down
Loading