Skip to content
Open
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
13 changes: 7 additions & 6 deletions python/pyspark/pandas/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2539,19 +2539,20 @@ def concat(
if len(objs) == 0:
raise ValueError("All objects passed were None")

psobjs: List[Union[DataFrame, Series]] = []
for obj in objs:
if not isinstance(obj, (Series, DataFrame)):
raise TypeError(
"cannot concatenate object of type "
"'{name}"
"; only ps.Series "
"and ps.DataFrame are valid".format(name=type(objs).__name__)
"'; only ps.Series and ps.DataFrame are valid".format(name=type(obj).__name__)
)
psobjs.append(obj)

if join not in ["inner", "outer"]:
raise ValueError("Only can inner (intersect) or outer (union) join the other axis.")

if all([obj.empty for obj in objs]):
if all([obj.empty for obj in psobjs]):
warnings.warn(
"The behavior of array concatenation with empty entries is "
"deprecated. In a future version, this will no longer exclude "
Expand All @@ -2565,7 +2566,7 @@ def concat(
psdf: DataFrame
if axis == 1:
psdfs: List[DataFrame] = [
obj.to_frame() if isinstance(obj, Series) else obj for obj in objs
obj.to_frame() if isinstance(obj, Series) else obj for obj in psobjs
]

level: int = min(psdf._internal.column_labels_level for psdf in psdfs)
Expand Down Expand Up @@ -2644,14 +2645,14 @@ def resolve_func(psdf, this_column_labels, that_column_labels):

# Series, Series ...
# We should return Series if objects are all Series.
should_return_series = all(map(lambda obj: isinstance(obj, Series), objs))
should_return_series = all(map(lambda obj: isinstance(obj, Series), psobjs))

# DataFrame, Series ... & Series, Series ...
# In this case, we should return DataFrame.
new_objs: List[DataFrame] = []
num_series = 0
series_names = set()
for obj in objs:
for obj in psobjs:
if isinstance(obj, Series):
num_series += 1
series_names.add(obj.name)
Expand Down
21 changes: 20 additions & 1 deletion python/pyspark/pandas/tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,26 @@ def test_concat_index_axis(self):
)

self.assertRaisesRegex(TypeError, "first argument must be", lambda: ps.concat(psdf))
self.assertRaisesRegex(TypeError, "cannot concatenate object", lambda: ps.concat([psdf, 1]))
self.assertRaisesRegex(
TypeError,
"cannot concatenate object of type 'DataFrame'",
lambda: ps.concat([pdf]),
)
self.assertRaisesRegex(
TypeError,
"cannot concatenate object of type 'Series'",
lambda: ps.concat([pdf["C"]]),
)
self.assertRaisesRegex(
TypeError,
"cannot concatenate object of type 'DataFrame'",
lambda: ps.concat([psdf, pdf]),
)
self.assertRaisesRegex(
TypeError,
"cannot concatenate object of type 'int'",
lambda: ps.concat([psdf, 1]),
)

psdf2 = psdf.set_index("B", append=True)
self.assertRaisesRegex(
Expand Down