Skip to content

Commit eddd5c9

Browse files
committed
TST: frame.py test coverage
1 parent a324d8d commit eddd5c9

File tree

3 files changed

+38
-46
lines changed

3 files changed

+38
-46
lines changed

pandas/core/common.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import cPickle
55
try:
66
from io import BytesIO
7-
except ImportError: # Python < 2.6
7+
except ImportError: # pragma: no cover
8+
# Python < 2.6
89
from cStringIO import StringIO as BytesIO
910
import itertools
1011

@@ -486,7 +487,8 @@ def __init__(self, seq, key=lambda x:x):
486487
self.setdefault(k, []).append(value)
487488
try:
488489
__iter__ = dict.iteritems
489-
except AttributeError: # Python 3
490+
except AttributeError: # pragma: no cover
491+
# Python 3
490492
def __iter__(self):
491493
return iter(dict.items(self))
492494

pandas/core/frame.py

+7-39
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def iteritems(self):
279279
return ((k, self[k]) for k in self.columns)
280280

281281
iterkv = iteritems
282-
if py3compat.PY3:
282+
if py3compat.PY3: # pragma: no cover
283283
items = iteritems
284284

285285
def __len__(self):
@@ -726,25 +726,6 @@ def _unpickle_matrix_compat(self, state): # pragma: no cover
726726

727727
self._data = dm._data
728728

729-
#----------------------------------------------------------------------
730-
# Private helper methods
731-
732-
def _intersect_index(self, other):
733-
common_index = self.index
734-
735-
if not common_index.equals(other.index):
736-
common_index = common_index.intersection(other.index)
737-
738-
return common_index
739-
740-
def _intersect_columns(self, other):
741-
common_cols = self.columns
742-
743-
if not common_cols.equals(other.columns):
744-
common_cols = common_cols.intersection(other.columns)
745-
746-
return common_cols
747-
748729
#----------------------------------------------------------------------
749730
# Array interface
750731

@@ -981,13 +962,9 @@ def xs(self, key, axis=0, copy=True):
981962
return Series(new_values, index=self.columns, name=key)
982963
else:
983964
new_data = self._data.xs(key, axis=1, copy=copy)
984-
if new_data.ndim == 1:
985-
return Series(new_data.as_matrix(), index=self.columns,
986-
name=key)
987-
else:
988-
result = DataFrame(new_data)
989-
result.index = _maybe_droplevels(result.index, key)
990-
return result
965+
result = DataFrame(new_data)
966+
result.index = _maybe_droplevels(result.index, key)
967+
return result
991968

992969
#----------------------------------------------------------------------
993970
# Reindexing and alignment
@@ -1465,15 +1442,6 @@ def _combine_frame(self, other, func, fill_value=None):
14651442
this, other = self.align(other, join='outer', copy=False)
14661443
new_index, new_columns = this.index, this.columns
14671444

1468-
# some shortcuts
1469-
if fill_value is None:
1470-
if not self and not other:
1471-
return self._constructor(index=new_index)
1472-
elif not self:
1473-
return other * nan
1474-
elif not other:
1475-
return self * nan
1476-
14771445
this_vals = this.values
14781446
other_vals = other.values
14791447

@@ -2174,7 +2142,7 @@ def join(self, other, on=None, how=None, lsuffix='', rsuffix=''):
21742142
return self._join_index(other, how, lsuffix, rsuffix)
21752143

21762144
def _join_on(self, other, on, how, lsuffix, rsuffix):
2177-
if how not in ['left', 'inner']:
2145+
if how not in ('left', 'inner'): # pragma: no cover
21782146
raise Exception('Only inner / left joins currently supported')
21792147

21802148
if isinstance(other, Series):
@@ -3295,7 +3263,7 @@ def _homogenize(data, index, columns, dtype=None):
32953263
def _put_str(s, space):
32963264
return ('%s' % s)[:space].ljust(space)
32973265

3298-
def install_ipython_completers():
3266+
def install_ipython_completers(): # pragma: no cover
32993267
"""Register the DataFrame type with IPython's tab completion machinery, so
33003268
that it knows about accessing column names as attributes."""
33013269
from IPython.utils.generics import complete_object
@@ -3307,7 +3275,7 @@ def complete_dataframe(obj, prev_completions):
33073275

33083276
# Importing IPython brings in about 200 modules, so we want to avoid it unless
33093277
# we're in IPython (when those modules are loaded anyway).
3310-
if "IPython" in sys.modules:
3278+
if "IPython" in sys.modules: # pragma: no cover
33113279
try:
33123280
install_ipython_completers()
33133281
except Exception:

pandas/tests/test_frame.py

+27-5
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,14 @@ def test_constructor_Series_copy_bug(self):
10951095
df = DataFrame(self.frame['A'], index=self.frame.index, columns=['A'])
10961096
df.copy()
10971097

1098+
def test_constructor_mixed_dict_and_Series(self):
1099+
data = {}
1100+
data['A'] = {'foo' : 1, 'bar' : 2, 'baz' : 3}
1101+
data['B'] = Series([4, 3, 2, 1], index=['bar', 'qux', 'baz', 'foo'])
1102+
1103+
result = DataFrame(data)
1104+
self.assert_(result.index.is_monotonic)
1105+
10981106
def test_astype(self):
10991107
casted = self.frame.astype(int)
11001108
expected = DataFrame(self.frame.values.astype(int),
@@ -1398,6 +1406,13 @@ def test_arith_flex_frame(self):
13981406
const_add = self.frame.add(1)
13991407
assert_frame_equal(const_add, self.frame + 1)
14001408

1409+
# corner cases
1410+
result = self.frame.add(self.frame[:0])
1411+
assert_frame_equal(result, self.frame * np.nan)
1412+
1413+
result = self.frame[:0].add(self.frame)
1414+
assert_frame_equal(result, self.frame * np.nan)
1415+
14011416
def test_arith_flex_series(self):
14021417
df = self.simple
14031418

@@ -2160,8 +2175,13 @@ def test_reindex_columns(self):
21602175
newFrame = self.frame.reindex(columns=[])
21612176
self.assert_(not newFrame)
21622177

2163-
def test_reindex_mixed(self):
2164-
pass
2178+
def test_align(self):
2179+
2180+
af, bf = self.frame.align(self.frame)
2181+
self.assert_(af._data is not self.frame._data)
2182+
2183+
af, bf = self.frame.align(self.frame, copy=False)
2184+
self.assert_(af._data is self.frame._data)
21652185

21662186
#----------------------------------------------------------------------
21672187
# Transposing
@@ -3195,6 +3215,11 @@ def test_join_on_multikey(self):
31953215
# TODO: columns aren't in the same order yet
31963216
assert_frame_equal(joined, expected.ix[:, joined.columns])
31973217

3218+
def test_join_on_series(self):
3219+
result = self.target.join(self.source['MergedA'], on='C')
3220+
expected = self.target.join(self.source[['MergedA']], on='C')
3221+
assert_frame_equal(result, expected)
3222+
31983223
def test_join_index_mixed(self):
31993224

32003225
df1 = DataFrame({'A' : 1., 'B' : 2, 'C' : 'foo', 'D' : True},
@@ -3234,9 +3259,6 @@ def test_join_index_mixed(self):
32343259
expected = _join_by_hand(df2, df1, how=kind)
32353260
assert_frame_equal(joined, expected)
32363261

3237-
def test_join_on_series(self):
3238-
pass
3239-
32403262
def test_join_empty_bug(self):
32413263
# generated an exception in 0.4.3
32423264
x = DataFrame()

0 commit comments

Comments
 (0)