Skip to content
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

BUG: avoid DeprecationWarning when the Series has index as list of Series (#55395) #56325

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ Fixed regressions

Bug fixes
~~~~~~~~~
- Bug in :class:`Series` constructor raising DeprecationWarning when ``index`` is a list of :class:`Series` (:issue:`55228`)
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55753`)
- Bug in :meth:`Index.__getitem__` returning wrong result for Arrow dtypes and negative stepsize (:issue:`55832`)
- Fixed bug in :func:`to_numeric` converting to extension dtype for ``string[pyarrow_numpy]`` dtype (:issue:`56179`)
- Fixed bug in :meth:`DataFrame.__setitem__` casting :class:`Index` with object-dtype to PyArrow backed strings when ``infer_string`` option is set (:issue:`55638`)
- Fixed bug in :meth:`DataFrame.to_hdf` raising when columns have ``StringDtype`` (:issue:`55088`)
- Fixed bug in :meth:`Index.insert` casting object-dtype to PyArrow backed strings when ``infer_string`` option is set (:issue:`55638`)
- Fixed bug in :meth:`Series.str.translate` losing object dtype when string option is set (:issue:`56152`)
-

.. ---------------------------------------------------------------------------
.. _whatsnew_214.other:
Expand Down
10 changes: 8 additions & 2 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,16 @@ def is_all_arraylike(obj: list) -> bool:
object val
bint all_arrays = True

from pandas.core.dtypes.generic import (
ABCIndex,
ABCMultiIndex,
ABCSeries,
)

for i in range(n):
val = obj[i]
if not (isinstance(val, list) or
util.is_array(val) or hasattr(val, "_data")):
if (not (isinstance(val, (list, ABCSeries, ABCIndex)) or util.is_array(val))
or isinstance(val, ABCMultiIndex)):
# TODO: EA?
# exclude tuples, frozensets as they may be contained in an Index
all_arrays = False
Expand Down
18 changes: 8 additions & 10 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,16 +2150,14 @@ def test_series_constructor_datetimelike_index_coercion(self):
# to DatetimeIndex GH#39307, GH#23598
assert not isinstance(ser.index, DatetimeIndex)

def test_series_constructor_infer_multiindex(self):
index_lists = [["a", "a", "b", "b"], ["x", "y", "x", "y"]]

multi = Series(1.0, index=[np.array(x) for x in index_lists])
assert isinstance(multi.index, MultiIndex)

multi = Series(1.0, index=index_lists)
assert isinstance(multi.index, MultiIndex)

multi = Series(range(4), index=index_lists)
@pytest.mark.parametrize("container", [None, np.array, Series, Index])
@pytest.mark.parametrize("data", [1.0, range(4)])
def test_series_constructor_infer_multiindex(self, container, data):
indexes = [["a", "a", "b", "b"], ["x", "y", "x", "y"]]
if container is not None:
indexes = [container(ind) for ind in indexes]

multi = Series(data, index=indexes)
assert isinstance(multi.index, MultiIndex)


Expand Down