Skip to content

Commit c2283f1

Browse files
committed
TST: misc test coverage
1 parent 3876f9d commit c2283f1

File tree

5 files changed

+57
-21
lines changed

5 files changed

+57
-21
lines changed

pandas/core/frame.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,10 @@ def dot(self, other):
749749
"""
750750
if isinstance(other, (Series, DataFrame)):
751751
common = self.columns.union(other.index)
752-
if len(common) > len(self.columns) or len(common) > len(other.index):
752+
if (len(common) > len(self.columns) or
753+
len(common) > len(other.index)):
753754
raise ValueError('matrices are not aligned')
755+
754756
left = self.reindex(columns=common, copy=False)
755757
right = other.reindex(index=common, copy=False)
756758
lvals = left.values
@@ -775,7 +777,7 @@ def dot(self, other):
775777
return DataFrame(result, index=left.index)
776778
else:
777779
return Series(result, index=left.index)
778-
else:
780+
else: # pragma: no cover
779781
raise TypeError('unsupported type: %s' % type(other))
780782

781783
#----------------------------------------------------------------------
@@ -2086,10 +2088,7 @@ def xs(self, key, axis=0, level=None, copy=True):
20862088
if isinstance(loc, np.ndarray):
20872089
if loc.dtype == np.bool_:
20882090
inds, = loc.nonzero()
2089-
if len(inds) == 1:
2090-
loc = inds[0]
2091-
else:
2092-
return self.take(inds, axis=axis)
2091+
return self.take(inds, axis=axis)
20932092
else:
20942093
return self.take(loc, axis=axis)
20952094

@@ -3946,8 +3945,8 @@ def _apply_broadcast(self, func, axis):
39463945
target = self
39473946
elif axis == 1:
39483947
target = self.T
3949-
else:
3950-
raise ValueError('Axis must be 0 or 1, got %s' % str(axis))
3948+
else: # pragma: no cover
3949+
raise ValueError('Axis must be 0 or 1, got %s' % axis)
39513950

39523951
result_values = np.empty_like(target.values)
39533952
columns = target.columns
@@ -4563,8 +4562,7 @@ def _reduce(self, op, axis=0, skipna=True, numeric_only=None,
45634562
elif filter_type == 'bool':
45644563
data = self._get_bool_data()
45654564
else:
4566-
raise ValueError('Invalid filter_type %s ' %
4567-
str(filter_type))
4565+
raise NotImplementedError
45684566
result = f(data.values)
45694567
labels = data._get_agg_axis(axis)
45704568
else:
@@ -4574,8 +4572,7 @@ def _reduce(self, op, axis=0, skipna=True, numeric_only=None,
45744572
elif filter_type == 'bool':
45754573
data = self._get_bool_data()
45764574
else:
4577-
raise ValueError('Invalid filter_type %s ' %
4578-
str(filter_type))
4575+
raise NotImplementedError
45794576
values = data.values
45804577
labels = data._get_agg_axis(axis)
45814578
else:
@@ -4589,7 +4586,7 @@ def _reduce(self, op, axis=0, skipna=True, numeric_only=None,
45894586
elif filter_type == 'bool' and notnull(result).all():
45904587
result = result.astype(np.bool_)
45914588
else:
4592-
raise ValueError('Invalid dtype %s ' % str(filter_type))
4589+
raise NotImplementedError
45934590

45944591
except (ValueError, TypeError):
45954592
pass
@@ -4950,8 +4947,7 @@ def group_agg(values, bounds, f):
49504947
result = np.empty((len(bounds), K), dtype=float)
49514948

49524949
testagg = f(values[:min(1, len(values))])
4953-
if isinstance(testagg, np.ndarray) and testagg.ndim == 2:
4954-
raise Exception('Passed function does not aggregate!')
4950+
assert(not (isinstance(testagg, np.ndarray) and testagg.ndim == 2))
49554951

49564952
for i, left_bound in enumerate(bounds):
49574953
if i == len(bounds) - 1:
@@ -5132,13 +5128,9 @@ def _to_arrays(data, columns, coerce_float=False):
51325128
def _list_to_arrays(data, columns, coerce_float=False):
51335129
if len(data) > 0 and isinstance(data[0], tuple):
51345130
content = list(lib.to_object_array_tuples(data).T)
5135-
elif len(data) > 0:
5131+
else:
51365132
# list of lists
51375133
content = list(lib.to_object_array(data).T)
5138-
else:
5139-
if columns is None:
5140-
columns = []
5141-
return {}, columns
51425134
return _convert_object_array(content, columns,
51435135
coerce_float=coerce_float)
51445136

pandas/core/panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ def join(self, other, how='left', lsuffix='', rsuffix=''):
13391339
join_axes=join_axes, verify_integrity=True)
13401340

13411341
def update(self, other, join='left', overwrite=True, filter_func=None,
1342-
raise_conflict=False):
1342+
raise_conflict=False):
13431343
"""
13441344
Modify Panel in place using non-NA values from passed
13451345
Panel, or object coercible to Panel. Aligns on items

pandas/tests/test_format.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,10 @@ def test_dict_entries(self):
791791
val = df.to_string()
792792
self.assertTrue("{'a': 1, 'b': 2}" in val)
793793

794+
def test_to_latex(self):
795+
# it works!
796+
self.frame.to_latex()
797+
794798
class TestSeriesFormatting(unittest.TestCase):
795799

796800
def setUp(self):

pandas/tests/test_frame.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,16 @@ def test_set_index2(self):
15541554
xp.index.names = [None, 'A', 'B']
15551555
assert_frame_equal(result, xp)
15561556

1557+
# append to existing multiindex
1558+
rdf = df.set_index(['A'], append=True)
1559+
rdf = rdf.set_index(['B', 'C'], append=True)
1560+
expected = df.set_index(['A', 'B', 'C'], append=True)
1561+
assert_frame_equal(rdf, expected)
1562+
1563+
# Series
1564+
result = df.set_index(df.C)
1565+
self.assertEqual(result.index.name, 'C')
1566+
15571567
def test_set_index_nonuniq(self):
15581568
df = DataFrame({'A' : ['foo', 'foo', 'foo', 'bar', 'bar'],
15591569
'B' : ['one', 'two', 'three', 'one', 'two'],
@@ -3059,6 +3069,16 @@ def test_arith_flex_frame(self):
30593069
result = self.frame[:0].add(self.frame)
30603070
assert_frame_equal(result, self.frame * np.nan)
30613071

3072+
def test_arith_mixed(self):
3073+
3074+
left = DataFrame({'A': ['a', 'b', 'c'],
3075+
'B': [1, 2, 3]})
3076+
3077+
result = left + left
3078+
expected = DataFrame({'A': ['aa', 'bb', 'cc'],
3079+
'B': [2, 4, 6]})
3080+
assert_frame_equal(result, expected)
3081+
30623082
def test_bool_flex_frame(self):
30633083
data = np.random.randn(5, 3)
30643084
other_data = np.random.randn(5, 3)
@@ -4791,6 +4811,13 @@ def test_xs_corner(self):
47914811
expected = Series([])
47924812
assert_series_equal(result, expected)
47934813

4814+
def test_xs_duplicates(self):
4815+
df = DataFrame(randn(5, 2), index=['b', 'b', 'c', 'b', 'a'])
4816+
4817+
cross = df.xs('c')
4818+
exp = df.irow(2)
4819+
assert_series_equal(cross, exp)
4820+
47944821
def test_pivot(self):
47954822
data = {
47964823
'index' : ['A', 'B', 'C', 'C', 'B', 'A'],
@@ -7184,6 +7211,12 @@ def test_dot(self):
71847211
# it works
71857212
result = A.dot(b)
71867213

7214+
# unaligned
7215+
df = DataFrame(randn(3, 4), index=[1, 2, 3], columns=range(4))
7216+
df2 = DataFrame(randn(5, 3), index=range(5), columns=[1, 2, 3])
7217+
7218+
self.assertRaises(ValueError, df.dot, df2)
7219+
71877220
def test_idxmin(self):
71887221
frame = self.frame
71897222
frame.ix[5:10] = np.nan

pandas/tests/test_panel.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,13 @@ def test_to_frame(self):
10151015
# names
10161016
self.assertEqual(unfiltered.index.names, ['major', 'minor'])
10171017

1018+
# unsorted, round trip
1019+
df = self.panel.to_frame(filter_observations=False)
1020+
unsorted = df.take(np.random.permutation(len(df)))
1021+
foo
1022+
pan = unsorted.to_panel()
1023+
assert_panel_equal(pan, self.panel)
1024+
10181025
# preserve original index names
10191026
df = DataFrame(np.random.randn(6, 2),
10201027
index=[['a', 'a', 'b', 'b', 'c', 'c'],

0 commit comments

Comments
 (0)