Skip to content

Commit b86dcb6

Browse files
committed
BUG: Concat with inner join and empty DataFrame
1 parent d9e75c7 commit b86dcb6

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,5 @@ Bug Fixes
580580
- Bug in ``Series.replace`` and ``DataFrame.replace`` which failed on empty replacement dicts (:issue:`15289`)
581581
- Bug in ``pd.melt()`` where passing a tuple value for ``value_vars`` caused a ``TypeError`` (:issue:`15348`)
582582
- Bug in ``.eval()`` which caused multiline evals to fail with local variables not on the first line (:issue:`15342`)
583+
584+
- Bug in ``pd.concat()`` in which empty dataframe with ``join='inner'`` was being improperly handled (:issue:`15328`)

pandas/tests/tools/test_concat.py

+9
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,15 @@ def test_concat_bug_3602(self):
18251825
result = concat([df1, df2], axis=1)
18261826
assert_frame_equal(result, expected)
18271827

1828+
def test_concat_bug_15328(self):
1829+
df_empty = pd.DataFrame()
1830+
df_a = pd.DataFrame({'a': [1, 2]}, index=[0, 1])
1831+
result = pd.concat([df_empty, df_a], axis=1, join='inner')
1832+
self.assertTrue(result.empty)
1833+
1834+
result = pd.concat([df_a, df_empty], axis=1, join='inner')
1835+
self.assertTrue(result.empty)
1836+
18281837
def test_concat_series_axis1_same_names_ignore_index(self):
18291838
dates = date_range('01-Jan-2013', '01-Jan-2014', freq='MS')[0:-1]
18301839
s1 = Series(randn(len(dates)), index=dates, name='value')

pandas/tests/tools/test_merge.py

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def setUp(self):
5454
self.right = DataFrame({'v2': np.random.randn(4)},
5555
index=['d', 'b', 'c', 'a'])
5656

57+
def test_merge_bug_15328(self):
58+
df_empty = pd.DataFrame()
59+
df_a = pd.DataFrame({'a': [1, 2]}, index=[0, 1])
60+
result = pd.merge(df_empty, df_a, left_index=True, right_index=True)
61+
self.assertTrue(result.empty)
62+
5763
def test_merge_common(self):
5864
joined = merge(self.df, self.df2)
5965
exp = merge(self.df, self.df2, on=['key1', 'key2'])

pandas/tools/concat.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
284284
if sum(obj.shape) > 0 or isinstance(obj, Series)]
285285

286286
if (len(non_empties) and (keys is None and names is None and
287-
levels is None and join_axes is None)):
287+
levels is None and
288+
join_axes is None and
289+
not self.intersect)):
288290
objs = non_empties
289291
sample = objs[0]
290292

0 commit comments

Comments
 (0)