Skip to content

TST: Tests for multi-index construction of an all-nan frame (GH4078) #5089

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

Merged
merged 1 commit into from
Oct 2, 2013
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ Bug Fixes
- Bug in setting with ``ix/loc`` and a mixed int/string index (:issue:`4544`)
- Make sure series-series boolean comparions are label based (:issue:`4947`)
- Bug in multi-level indexing with a Timestamp partial indexer (:issue:`4294`)
- Tests/fix for multi-index construction of an all-nan frame (:isue:`4078`)

pandas 0.12.0
-------------
Expand Down
13 changes: 10 additions & 3 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3530,9 +3530,16 @@ def _shape_compat(x):
if ref_items.is_unique:
items = ref_items[ref_items.isin(names)]
else:
items = _ensure_index([n for n in names if n in ref_items])
if len(items) != len(stacked):
raise Exception("invalid names passed _stack_arrays")
# a mi
if isinstance(ref_items, MultiIndex):
names = MultiIndex.from_tuples(names)
items = ref_items[ref_items.isin(names)]

# plain old dups
else:
items = _ensure_index([n for n in names if n in ref_items])
if len(items) != len(stacked):
raise ValueError("invalid names passed _stack_arrays")

return items, stacked, placement

Expand Down
21 changes: 17 additions & 4 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2263,10 +2263,6 @@ def test_constructor_overflow_int64(self):
df_crawls = DataFrame(data)
self.assert_(df_crawls['uid'].dtype == object)

def test_is_mixed_type(self):
self.assert_(not self.frame._is_mixed_type)
self.assert_(self.mixed_frame._is_mixed_type)

def test_constructor_ordereddict(self):
import random
nitems = 100
Expand Down Expand Up @@ -2319,6 +2315,19 @@ def test_constructor_dict(self):
frame = DataFrame({'A': [], 'B': []}, columns=['A', 'B'])
self.assert_(frame.index.equals(Index([])))

def test_constructor_multi_index(self):
# GH 4078
# construction error with mi and all-nan frame
tuples = [(2, 3), (3, 3), (3, 3)]
mi = MultiIndex.from_tuples(tuples)
df = DataFrame(index=mi,columns=mi)
self.assert_(pd.isnull(df).values.ravel().all())

tuples = [(3, 3), (2, 3), (3, 3)]
mi = MultiIndex.from_tuples(tuples)
df = DataFrame(index=mi,columns=mi)
self.assert_(pd.isnull(df).values.ravel().all())

def test_constructor_error_msgs(self):
msg = "Mixing dicts with non-Series may lead to ambiguous ordering."
# mix dict and array, wrong size
Expand Down Expand Up @@ -9489,6 +9498,10 @@ def test_get_X_columns(self):
self.assert_(np.array_equal(df._get_numeric_data().columns,
['a', 'b', 'e']))

def test_is_mixed_type(self):
self.assert_(not self.frame._is_mixed_type)
self.assert_(self.mixed_frame._is_mixed_type)

def test_get_numeric_data(self):
intname = np.dtype(np.int_).name
floatname = np.dtype(np.float_).name
Expand Down