Skip to content

Commit df30233

Browse files
committed
Fix bug and error message
1 parent 787eca4 commit df30233

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

pandas/core/reshape/concat.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
from pandas._libs import lib
1919
from pandas.util._exceptions import find_stack_level
2020

21-
from pandas.core.dtypes.common import (
22-
is_bool,
23-
is_iterator,
24-
is_list_like,
25-
)
21+
from pandas.core.dtypes.common import is_bool
2622
from pandas.core.dtypes.concat import concat_compat
2723
from pandas.core.dtypes.generic import (
2824
ABCDataFrame,
@@ -519,15 +515,18 @@ def _get_result(
519515

520516
res = concat_compat(arrs, axis=0)
521517

522-
new_index = _get_concat_axis_series(
523-
objs,
524-
ignore_index,
525-
bm_axis,
526-
keys,
527-
levels,
528-
verify_integrity,
529-
names,
530-
)
518+
if ignore_index:
519+
new_index = default_index(len(res))
520+
else:
521+
new_index = _get_concat_axis_series(
522+
objs,
523+
ignore_index,
524+
bm_axis,
525+
keys,
526+
levels,
527+
verify_integrity,
528+
names,
529+
)
531530

532531
mgr = type(sample._mgr).from_array(res, index=new_index)
533532

@@ -613,10 +612,8 @@ def new_axes(
613612
objs,
614613
axis,
615614
ignore_index,
616-
bm_axis,
617615
keys,
618616
names,
619-
axis,
620617
levels,
621618
verify_integrity,
622619
)
@@ -645,7 +642,12 @@ def _get_concat_axis_series(
645642
return default_index(len(objs))
646643
elif bm_axis == 0:
647644
indexes = [x.index for x in objs]
648-
concat_axis = _make_concat_multiindex(indexes, keys, levels, names)
645+
if keys is None:
646+
if levels is not None:
647+
raise ValueError("levels supported only when keys is not None")
648+
concat_axis = _concat_indexes(indexes)
649+
else:
650+
concat_axis = _make_concat_multiindex(indexes, keys, levels, names)
649651
if verify_integrity and not concat_axis.is_unique:
650652
overlap = concat_axis[concat_axis.duplicated()].unique()
651653
raise ValueError(f"Indexes have overlapping values: {overlap}")
@@ -724,12 +726,14 @@ def _clean_keys_and_objs(
724726
if keys is None:
725727
keys = objs.keys()
726728
objs = [objs[k] for k in keys]
727-
elif not is_list_like(objs):
729+
elif isinstance(objs, (ABCSeries, ABCDataFrame, str)):
728730
raise TypeError(
729731
"first argument must be an iterable of pandas "
730732
f'objects, you passed an object of type "{type(objs).__name__}"'
731733
)
732-
elif is_iterator(objs):
734+
elif isinstance(objs, (list, tuple, np.ndarray)):
735+
pass
736+
else:
733737
objs = list(objs)
734738

735739
if len(objs) == 0:

pandas/tests/generic/test_frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ def finalize(self, other, method=None, **kwargs):
8484
value = getattr(left, name, "") + "|" + getattr(right, name, "")
8585
object.__setattr__(self, name, value)
8686
elif method == "concat":
87+
objs = kwargs["objs"]
8788
value = "+".join(
88-
[getattr(o, name) for o in other.objs if getattr(o, name, None)]
89+
[getattr(o, name) for o in objs if getattr(o, name, None)]
8990
)
9091
object.__setattr__(self, name, value)
9192
else:

pandas/tests/generic/test_series.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,9 @@ def test_metadata_propagation_indiv(self, monkeypatch):
9494
def finalize(self, other, method=None, **kwargs):
9595
for name in self._metadata:
9696
if method == "concat" and name == "filename":
97+
objs = kwargs["objs"]
9798
value = "+".join(
98-
[
99-
getattr(obj, name)
100-
for obj in other.objs
101-
if getattr(obj, name, None)
102-
]
99+
[getattr(obj, name) for obj in objs if getattr(obj, name, None)]
103100
)
104101
object.__setattr__(self, name, value)
105102
else:
Binary file not shown.

0 commit comments

Comments
 (0)