Skip to content

Commit

Permalink
TST: test coverage enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
adamklein committed Mar 15, 2012
1 parent 3b8a192 commit 12d511f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _get_item_cache(self, item):
res = self._box_item_values(item, values)
cache[item] = res
return res
except Exception:
except Exception: # pragma: no cover
from pandas.core.frame import DataFrame
if isinstance(item, DataFrame):
raise ValueError('Cannot index using (boolean) dataframe')
Expand Down
14 changes: 5 additions & 9 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,11 @@ def _getitem_multilevel(self, key):
if isinstance(loc, (slice, np.ndarray)):
new_index = self.items[loc]
result_index = _maybe_droplevels(new_index, key)
if self._is_mixed_type:
result = self.reindex(items=new_index)
result.index = result_index
else:
new_values = self.values[loc, :, :]
result = Panel(new_values,
items=result_index,
major_axis=self.major_axis,
minor_axis=self.minor_axis)
new_values = self.values[loc, :, :]
result = Panel(new_values,
items=result_index,
major_axis=self.major_axis,
minor_axis=self.minor_axis)
return result
else:
return self._get_item_cache(key)
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,10 @@ def test_align(self):
method=None, fill_value=None)
self.assert_(bf.index.equals(Index([])))

af, bf = self.frame.align(other.ix[:,0], join='inner', axis=1,
method=None, fill_value=0)
self.assert_(bf.index.equals(Index([])))

# try to align dataframe to series along bad axis
self.assertRaises(ValueError, self.frame.align, af.ix[0,:3],
join='inner', axis=2)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def test_plot(self):
_check_plot_works(self.ts[:10].plot, kind='bar')
_check_plot_works(self.series[:5].plot, kind='bar')
_check_plot_works(self.series[:5].plot, kind='line')

_check_plot_works(self.series[:5].plot, kind='barh')
_check_plot_works(self.series[:10].plot, kind='barh')
@slow
def test_hist(self):
_check_plot_works(self.ts.hist)
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,9 @@ def test_diff(self):
def test_from_tuples(self):
self.assertRaises(Exception, MultiIndex.from_tuples, [])

idx = MultiIndex.from_tuples( ((1,2),(3,4)), names=['a', 'b'] )
self.assertEquals(len(idx), 2)

def test_argsort(self):
result = self.index.argsort()
expected = self.index.get_tuple_index().argsort()
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,20 @@ def test_multiindex_get(self):
self.assert_((f1.items == [1, 2]).all())
self.assert_((f2.items == [1, 2]).all())

ind = MultiIndex.from_tuples([('a', 1), ('a', 2), ('b', 1)],
names=['first', 'second'])

def test_multiindex_blocks(self):
ind = MultiIndex.from_tuples([('a', 1), ('a', 2), ('b', 1)],
names=['first', 'second'])
wp = Panel(self.panel._data)
wp.items = ind
f1 = wp['a']
self.assert_((f1.items == [1, 2]).all())

f1 = wp[('b',1)]
self.assert_((f1.columns == ['A', 'B', 'C', 'D']).all())

def test_repr_empty(self):
empty = Panel()
repr(empty)
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ def test_constructor_corner(self):
s = Series(objs, index=[0, 1])
self.assert_(isinstance(s, Series))

def test_constructor_sanitize(self):
s = Series(np.array([1., 1., 8.]), dtype='i8')
self.assertEquals(s.dtype, np.dtype('i8'))

s = Series(np.array([1., 1., np.nan]), copy=True, dtype='i8')
self.assertEquals(s.dtype, np.dtype('f8'))

def test_constructor_pass_none(self):
s = Series(None, index=range(5))
self.assert_(s.dtype == np.float64)
Expand Down

0 comments on commit 12d511f

Please sign in to comment.