Skip to content

Commit 183764d

Browse files
committed
BUG: work around matplotlib-related buglet, Index inserting newaxis issue
1 parent dfd2926 commit 183764d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pandas/core/index.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def __new__(cls, data, dtype=None, copy=False, name=None):
5959
if isinstance(data, np.ndarray):
6060
if dtype is None and issubclass(data.dtype.type, np.integer):
6161
return Int64Index(data, copy=copy, name=name)
62+
6263
subarr = np.array(data, dtype=object, copy=copy)
6364
elif np.isscalar(data):
6465
raise ValueError('Index(...) must be called with a collection '
@@ -209,7 +210,11 @@ def __getitem__(self, key):
209210
if _is_bool_indexer(key):
210211
key = np.asarray(key)
211212

212-
return Index(arr_idx[key], name=self.name)
213+
result = arr_idx[key]
214+
if result.ndim > 1:
215+
return result
216+
217+
return Index(result, name=self.name)
213218

214219
def append(self, other):
215220
"""

pandas/tests/test_index.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def setUp(self):
2424
def test_hash_error(self):
2525
self.assertRaises(TypeError, hash, self.strIndex)
2626

27+
def test_new_axis(self):
28+
new_index = self.dateIndex[None, :]
29+
self.assert_(new_index.ndim == 2)
30+
self.assert_(type(new_index) == np.ndarray)
31+
2732
def test_deepcopy(self):
2833
from copy import deepcopy
2934

0 commit comments

Comments
 (0)