Skip to content

Commit 29846da

Browse files
committed
BUG: allow MultiIndex setops with all length-0 indexes close pandas-dev#1727
1 parent 3c5621b commit 29846da

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pandas 0.8.2
8383
- Fix re: unicode MultiIndex level names in Series/DataFrame repr (#1736)
8484
- Handle PeriodIndex in to_datetime instance method (#1703)
8585
- Support StaticTzInfo in DatetimeIndex infrastructure (#1692)
86+
- Allow MultiIndex setops with length-0 other type indexes (#1727)
8687

8788
pandas 0.8.1
8889
============

pandas/core/index.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,8 @@ def diff(self, other):
22852285

22862286
def _assert_can_do_setop(self, other):
22872287
if not isinstance(other, MultiIndex):
2288+
if len(other) == 0:
2289+
return True
22882290
raise TypeError('can only call with other hierarchical '
22892291
'index objects')
22902292

pandas/tests/test_multilevel.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,18 @@ def test_set_column_scalar_with_ix(self):
14321432
col[subset] = 97
14331433
self.assert_((self.frame.ix[subset, 'B'] == 97).all())
14341434

1435+
def test_frame_dict_constructor_empty_series(self):
1436+
s1 = Series([1,2,3, 4], index=MultiIndex.from_tuples([(1,2),(1,3),
1437+
(2,2),(2,4)]))
1438+
s2 = Series([1,2,3,4],
1439+
index=MultiIndex.from_tuples([(1,2),(1,3),(3,2),(3,4)]))
1440+
s3 = Series()
1441+
1442+
# it works!
1443+
df = DataFrame({'foo':s1, 'bar':s2, 'baz':s3})
1444+
df = DataFrame.from_dict({'foo':s1, 'baz':s3, 'bar':s2})
1445+
1446+
14351447
if __name__ == '__main__':
14361448

14371449
# unittest.main()

0 commit comments

Comments
 (0)