Skip to content

Commit ed383bd

Browse files
committed
TST: added core coverage
1 parent 0cb2a82 commit ed383bd

10 files changed

+113
-26
lines changed

pandas/core/common.py

-10
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,6 @@ def console_encode(value):
630630
except (AttributeError, TypeError):
631631
return value.encode('ascii', 'replace')
632632

633-
def csv_encode(value, encoding='UTF-8'):
634-
if py3compat.PY3 or not isinstance(value, unicode):
635-
return value
636-
637-
return value.encode(encoding, 'replace')
638-
639633
class UTF8Recoder:
640634
"""
641635
Iterator that reads an encoded stream and reencodes the input to UTF-8
@@ -709,7 +703,3 @@ def writerow(self, row):
709703
self.stream.write(data)
710704
# empty queue
711705
self.queue.truncate(0)
712-
713-
def writerows(self, rows):
714-
for row in rows:
715-
self.writerow(row)

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ def sort(self, columns=None, column=None, axis=0, ascending=True):
22452245
-------
22462246
sorted : DataFrame
22472247
"""
2248-
if column is not None:
2248+
if column is not None: # pragma: no cover
22492249
import warnings
22502250
warnings.warn("column is deprecated, use columns", FutureWarning)
22512251
columns = column

pandas/core/internals.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _pad(values):
229229
_method = lib.pad_2d_inplace_float64
230230
elif values.dtype == np.object_:
231231
_method = lib.pad_2d_inplace_object
232-
else:
232+
else: # pragma: no cover
233233
raise ValueError('Invalid dtype for padding')
234234

235235
_method(values, com.isnull(values).view(np.uint8))
@@ -239,7 +239,7 @@ def _backfill(values):
239239
_method = lib.backfill_2d_inplace_float64
240240
elif values.dtype == np.object_:
241241
_method = lib.backfill_2d_inplace_object
242-
else:
242+
else: # pragma: no cover
243243
raise ValueError('Invalid dtype for padding')
244244

245245
_method(values, com.isnull(values).view(np.uint8))
@@ -608,9 +608,6 @@ def consolidate(self):
608608
return BlockManager(new_blocks, self.axes)
609609

610610
def _consolidate_inplace(self):
611-
if self.is_consolidated():
612-
return
613-
614611
self.blocks = _consolidate(self.blocks, self.items)
615612

616613
def get(self, item):

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def wrapper(self, other):
108108
name = _maybe_match_name(self, other)
109109
return Series(na_op(self.values, other.values),
110110
index=self.index, name=name)
111-
elif isinstance(other, DataFrame):
111+
elif isinstance(other, DataFrame): # pragma: no cover
112112
return NotImplemented
113113
else:
114114
# scalars

pandas/tests/test_format.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def test_to_string_no_index(self):
187187

188188
def test_to_string_float_formatting(self):
189189
fmt.reset_printoptions()
190-
fmt.set_printoptions(precision=6, column_space=12)
190+
fmt.set_printoptions(precision=6, column_space=12,
191+
notebook_repr_html=False)
191192

192193
df = DataFrame({'x' : [0, 0.25, 3456.000, 12e+45, 1.64e+6,
193194
1.7e+8, 1.253456, np.pi, -1e6]})
@@ -341,6 +342,13 @@ def test_to_html_with_no_bold(self):
341342
def test_repr_html(self):
342343
self.frame._repr_html_()
343344

345+
fmt.set_printoptions(max_rows=1, max_columns=1)
346+
self.frame._repr_html_()
347+
348+
fmt.set_printoptions(notebook_repr_html=False)
349+
self.frame._repr_html_()
350+
351+
fmt.reset_printoptions()
344352

345353
class TestSeriesFormatting(unittest.TestCase):
346354

pandas/tests/test_frame.py

+48-2
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,17 @@ def test_constructor(self):
11741174
df = DataFrame(data={})
11751175
self.assert_(len(df.index) == 0)
11761176

1177+
def test_list_to_sdict(self):
1178+
from pandas.core.frame import _list_to_sdict
1179+
1180+
d, c = _list_to_sdict([], None)
1181+
self.assertEquals(d, {})
1182+
self.assertEquals(c, [])
1183+
1184+
d, c = _list_to_sdict([], [])
1185+
self.assertEquals(d, {})
1186+
self.assertEquals(c, [])
1187+
11771188
def test_constructor_mixed(self):
11781189
index, data = tm.getMixedTypeDict()
11791190

@@ -1536,8 +1547,8 @@ def test_constructor_list_of_series(self):
15361547
data = [Series(d) for d in data]
15371548

15381549
result = DataFrame(data)
1539-
expected = DataFrame.from_dict(dict(zip(range(len(data)), data)),
1540-
orient='index')
1550+
sdict = dict(zip(range(len(data)), data))
1551+
expected = DataFrame.from_dict(sdict, orient='index')
15411552
assert_frame_equal(result, expected.reindex(result.index))
15421553

15431554
result2 = DataFrame(data, index=np.arange(6))
@@ -1547,6 +1558,15 @@ def test_constructor_list_of_series(self):
15471558
expected = DataFrame(index=[0])
15481559
assert_frame_equal(result, expected)
15491560

1561+
data = [{'a': 1.5, 'b': 3.0, 'c':4.0},
1562+
{'a': 1.5, 'b': 3.0, 'c':6.0}]
1563+
sdict = dict(zip(range(len(data)), data))
1564+
idx = Index(['a', 'b', 'c'])
1565+
data2 = [Series([1.5, 3, 4], idx, dtype='O'),
1566+
Series([1.5, 3, 6], idx)]
1567+
result = DataFrame(data2)
1568+
expected = DataFrame.from_dict(sdict, orient='index')
1569+
assert_frame_equal(result, expected)
15501570

15511571
def test_constructor_ragged(self):
15521572
data = {'A' : randn(10),
@@ -1893,6 +1913,10 @@ def test_repr(self):
18931913

18941914
fmt.set_printoptions(max_rows=10, max_columns=2)
18951915
repr(self.frame)
1916+
1917+
fmt.set_printoptions(max_rows=1000, max_columns=1000)
1918+
repr(self.frame)
1919+
18961920
fmt.reset_printoptions()
18971921

18981922
def test_head_tail(self):
@@ -3302,6 +3326,21 @@ def test_align(self):
33023326
af, bf = self.frame.align(other, join='inner', axis=1)
33033327
self.assert_(bf.columns.equals(other.columns))
33043328

3329+
af, bf = self.frame.align(other, join='inner', axis=1, method='pad')
3330+
self.assert_(bf.columns.equals(other.columns))
3331+
3332+
# test other non-float types
3333+
af, bf = self.intframe.align(other, join='inner', axis=1, method='pad')
3334+
self.assert_(bf.columns.equals(other.columns))
3335+
3336+
af, bf = self.mixed_frame.align(self.mixed_frame,
3337+
join='inner', axis=1, method='pad')
3338+
self.assert_(bf.columns.equals(self.mixed_frame.columns))
3339+
3340+
af, bf = self.frame.align(other.ix[:,0], join='inner', axis=1,
3341+
method=None, fill_value=None)
3342+
self.assert_(bf.index.equals(Index([])))
3343+
33053344
# try to align dataframe to series along bad axis
33063345
self.assertRaises(ValueError, self.frame.align, af.ix[0,:3],
33073346
join='inner', axis=2)
@@ -4614,6 +4653,13 @@ def test_consolidate(self):
46144653
self.frame.consolidate(inplace=True)
46154654
self.assert_(len(self.frame._data.blocks) == 1)
46164655

4656+
def test_consolidate_inplace(self):
4657+
frame = self.frame.copy()
4658+
4659+
# triggers in-place consolidation
4660+
for letter in range(ord('A'), ord('Z')):
4661+
self.frame[chr(letter)] = chr(letter)
4662+
46174663
def test_as_matrix_consolidate(self):
46184664
self.frame['E'] = 7.
46194665
self.assert_(not self.frame._data.is_consolidated())

pandas/tests/test_graphics.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class TestSeriesPlots(unittest.TestCase):
1414

1515
@classmethod
1616
def setUpClass(cls):
17-
import sys
18-
if 'IPython' in sys.modules:
19-
raise nose.SkipTest
17+
#import sys
18+
#if 'IPython' in sys.modules:
19+
# raise nose.SkipTest
2020

2121
try:
2222
import matplotlib as mpl
@@ -50,9 +50,9 @@ class TestDataFramePlots(unittest.TestCase):
5050

5151
@classmethod
5252
def setUpClass(cls):
53-
import sys
54-
if 'IPython' in sys.modules:
55-
raise nose.SkipTest
53+
#import sys
54+
#if 'IPython' in sys.modules:
55+
# raise nose.SkipTest
5656

5757
try:
5858
import matplotlib as mpl

pandas/tests/test_groupby.py

+29
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,25 @@ def test_agg_apply_corner(self):
204204
assert_frame_equal(grouped.agg(np.sum), DataFrame({}))
205205
assert_frame_equal(grouped.apply(np.sum), DataFrame({}))
206206

207+
def test_agg_grouping_is_list_tuple(self):
208+
from pandas.core.groupby import Grouping
209+
210+
df = tm.makeTimeDataFrame()
211+
212+
grouped = df.groupby(lambda x: x.year)
213+
grouper = grouped.grouper.groupings[0].grouper
214+
grouped.grouper.groupings[0] = Grouping(self.ts.index, list(grouper))
215+
216+
result = grouped.agg(np.mean)
217+
expected = grouped.mean()
218+
tm.assert_frame_equal(result, expected)
219+
220+
grouped.grouper.groupings[0] = Grouping(self.ts.index, tuple(grouper))
221+
222+
result = grouped.agg(np.mean)
223+
expected = grouped.mean()
224+
tm.assert_frame_equal(result, expected)
225+
207226
def test_agg_python_multiindex(self):
208227
grouped = self.mframe.groupby(['A', 'B'])
209228

@@ -475,6 +494,16 @@ def test_frame_groupby(self):
475494
samething = self.tsframe.index.take(indices[k])
476495
self.assert_(np.array_equal(v, samething))
477496

497+
def test_grouping_is_iterable(self):
498+
# this code path isn't used anywhere else
499+
# not sure it's useful
500+
grouped = self.tsframe.groupby([lambda x: x.weekday(),
501+
lambda x: x.year])
502+
503+
# test it works
504+
for g in grouped.grouper.groupings[0]:
505+
pass
506+
478507
def test_frame_groupby_columns(self):
479508
mapping = {
480509
'A' : 0, 'B' : 0, 'C' : 1, 'D' : 1

pandas/tests/test_panel.py

+7
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,13 @@ def test_fillna(self):
864864
assert_frame_equal(filled['ItemA'],
865865
self.panel['ItemA'].fillna(method='backfill'))
866866

867+
panel = self.panel.copy()
868+
panel['str'] = 'foo'
869+
870+
filled = panel.fillna(method='backfill')
871+
assert_frame_equal(filled['ItemA'],
872+
panel['ItemA'].fillna(method='backfill'))
873+
867874
empty = self.panel.reindex(items=[])
868875
filled = empty.fillna(0)
869876
assert_panel_equal(filled, empty)

pandas/tests/test_series.py

+10
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,15 @@ def test_between(self):
11491149
expected = s[5:16].dropna()
11501150
assert_series_equal(result, expected)
11511151

1152+
def test_scalar_na_cmp(self):
1153+
s = Series([2,3,4,5,6,7,8,9,10])
1154+
s[::2] = np.nan
1155+
1156+
def tester(a, b):
1157+
return a & b
1158+
1159+
self.assertRaises(ValueError, tester, s, datetime(2005,1,1))
1160+
11521161
def test_idxmin(self):
11531162
# test idxmin
11541163
# _check_stat_op approach can not be used here because of isnull check.
@@ -1258,6 +1267,7 @@ def test_operators_frame(self):
12581267

12591268
tm.assert_almost_equal(self.ts + self.ts, (self.ts + df)['A'])
12601269
tm.assert_almost_equal(self.ts ** self.ts, (self.ts ** df)['A'])
1270+
tm.assert_almost_equal(self.ts < self.ts, (self.ts < df)['A'])
12611271

12621272
def test_operators_combine(self):
12631273
def _check_fill(meth, op, a, b, fill_value=0):

0 commit comments

Comments
 (0)