Skip to content

Commit 7443bb7

Browse files
committed
Merge pull request pandas-dev#7248 from jreback/fix_print
TST/CLN: remove prints (esp of unicode), replacing with com.pprint_thing (GH7247)
2 parents 8793356 + 9a357af commit 7443bb7

10 files changed

+35
-42
lines changed

pandas/io/tests/test_data.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ def tearDownClass(cls):
318318
@network
319319
def test_get_options_data_warning(self):
320320
with assert_produces_warning():
321-
print('month: {0}, year: {1}'.format(self.month, self.year))
322321
try:
323322
self.aapl.get_options_data(month=self.month, year=self.year)
324323
except RemoteDataError as e:
@@ -327,7 +326,6 @@ def test_get_options_data_warning(self):
327326
@network
328327
def test_get_near_stock_price_warning(self):
329328
with assert_produces_warning():
330-
print('month: {0}, year: {1}'.format(self.month, self.year))
331329
try:
332330
calls_near, puts_near = self.aapl.get_near_stock_price(call=True,
333331
put=True,
@@ -339,7 +337,6 @@ def test_get_near_stock_price_warning(self):
339337
@network
340338
def test_get_call_data_warning(self):
341339
with assert_produces_warning():
342-
print('month: {0}, year: {1}'.format(self.month, self.year))
343340
try:
344341
self.aapl.get_call_data(month=self.month, year=self.year)
345342
except RemoteDataError as e:
@@ -348,7 +345,6 @@ def test_get_call_data_warning(self):
348345
@network
349346
def test_get_put_data_warning(self):
350347
with assert_produces_warning():
351-
print('month: {0}, year: {1}'.format(self.month, self.year))
352348
try:
353349
self.aapl.get_put_data(month=self.month, year=self.year)
354350
except RemoteDataError as e:

pandas/io/tests/test_pytables.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,15 +1506,15 @@ def test_big_table_frame(self):
15061506
recons = store.select('df')
15071507
assert isinstance(recons, DataFrame)
15081508

1509-
print("\nbig_table frame [%s] -> %5.2f" % (rows, time.time() - x))
1509+
com.pprint_thing("\nbig_table frame [%s] -> %5.2f" % (rows, time.time() - x))
15101510

15111511
def test_big_table2_frame(self):
15121512
# this is a really big table: 1m rows x 60 float columns, 20 string, 20 datetime
15131513
# columns
15141514
raise nose.SkipTest('no big table2 frame')
15151515

15161516
# create and write a big table
1517-
print("\nbig_table2 start")
1517+
com.pprint_thing("\nbig_table2 start")
15181518
import time
15191519
start_time = time.time()
15201520
df = DataFrame(np.random.randn(1000 * 1000, 60), index=range(int(
@@ -1524,7 +1524,7 @@ def test_big_table2_frame(self):
15241524
for x in range(20):
15251525
df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0)
15261526

1527-
print("\nbig_table2 frame (creation of df) [rows->%s] -> %5.2f"
1527+
com.pprint_thing("\nbig_table2 frame (creation of df) [rows->%s] -> %5.2f"
15281528
% (len(df.index), time.time() - start_time))
15291529

15301530
def f(chunksize):
@@ -1535,15 +1535,15 @@ def f(chunksize):
15351535

15361536
for c in [10000, 50000, 250000]:
15371537
start_time = time.time()
1538-
print("big_table2 frame [chunk->%s]" % c)
1538+
com.pprint_thing("big_table2 frame [chunk->%s]" % c)
15391539
rows = f(c)
1540-
print("big_table2 frame [rows->%s,chunk->%s] -> %5.2f"
1541-
% (rows, c, time.time() - start_time))
1540+
com.pprint_thing("big_table2 frame [rows->%s,chunk->%s] -> %5.2f"
1541+
% (rows, c, time.time() - start_time))
15421542

15431543
def test_big_put_frame(self):
15441544
raise nose.SkipTest('no big put frame')
15451545

1546-
print("\nbig_put start")
1546+
com.pprint_thing("\nbig_put start")
15471547
import time
15481548
start_time = time.time()
15491549
df = DataFrame(np.random.randn(1000 * 1000, 60), index=range(int(
@@ -1553,16 +1553,16 @@ def test_big_put_frame(self):
15531553
for x in range(20):
15541554
df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0)
15551555

1556-
print("\nbig_put frame (creation of df) [rows->%s] -> %5.2f"
1556+
com.pprint_thing("\nbig_put frame (creation of df) [rows->%s] -> %5.2f"
15571557
% (len(df.index), time.time() - start_time))
15581558

15591559
with ensure_clean_store(self.path, mode='w') as store:
15601560
start_time = time.time()
15611561
store = HDFStore(self.path, mode='w')
15621562
store.put('df', df)
15631563

1564-
print(df.get_dtype_counts())
1565-
print("big_put frame [shape->%s] -> %5.2f"
1564+
com.pprint_thing(df.get_dtype_counts())
1565+
com.pprint_thing("big_put frame [shape->%s] -> %5.2f"
15661566
% (df.shape, time.time() - start_time))
15671567

15681568
def test_big_table_panel(self):
@@ -1588,7 +1588,7 @@ def test_big_table_panel(self):
15881588
recons = store.select('wp')
15891589
assert isinstance(recons, Panel)
15901590

1591-
print("\nbig_table panel [%s] -> %5.2f" % (rows, time.time() - x))
1591+
com.pprint_thing("\nbig_table panel [%s] -> %5.2f" % (rows, time.time() - x))
15921592

15931593
def test_append_diff_item_order(self):
15941594

@@ -3538,9 +3538,9 @@ def test_string_select(self):
35383538
expected = df[df.x != 'none']
35393539
assert_frame_equal(result,expected)
35403540
except Exception as detail:
3541-
print("[{0}]".format(detail))
3542-
print(store)
3543-
print(expected)
3541+
com.pprint_thing("[{0}]".format(detail))
3542+
com.pprint_thing(store)
3543+
com.pprint_thing(expected)
35443544

35453545
df2 = df.copy()
35463546
df2.loc[df2.x=='','x'] = np.nan

pandas/tests/test_expressions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def run_arithmetic_test(self, df, other, assert_func, check_dtype=False,
9191
assert expected.dtype.kind == 'f'
9292
assert_func(expected, result)
9393
except Exception:
94-
print("Failed test with operator %r" % op.__name__)
94+
com.pprint_thing("Failed test with operator %r" % op.__name__)
9595
raise
9696

9797
def test_integer_arithmetic(self):
@@ -131,8 +131,8 @@ def run_binary_test(self, df, other, assert_func,
131131
assert not used_numexpr, "Used numexpr unexpectedly."
132132
assert_func(expected, result)
133133
except Exception:
134-
print("Failed test with operation %r" % arith)
135-
print("test_flex was %r" % test_flex)
134+
com.pprint_thing("Failed test with operation %r" % arith)
135+
com.pprint_thing("test_flex was %r" % test_flex)
136136
raise
137137

138138
def run_frame(self, df, other, binary_comp=None, run_binary=True,

pandas/tests/test_format.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import pandas.core.format as fmt
2020
import pandas.util.testing as tm
21+
import pandas.core.common as com
2122
from pandas.util.terminal import get_terminal_size
2223
import pandas
2324
import pandas.tslib as tslib
@@ -288,7 +289,7 @@ def mkframe(n):
288289
df = mkframe((term_width // 7) - 2)
289290
self.assertFalse(has_expanded_repr(df))
290291
df = mkframe((term_width // 7) + 2)
291-
print( df._repr_fits_horizontal_())
292+
com.pprint_thing(df._repr_fits_horizontal_())
292293
self.assertTrue(has_expanded_repr(df))
293294

294295
def test_to_string_repr_unicode(self):
@@ -411,8 +412,6 @@ def test_to_string_truncate_indices(self):
411412
self.assertFalse(has_vertically_truncated_repr(df))
412413
with option_context("display.max_columns", 15):
413414
if w == 20:
414-
print(df)
415-
print(repr(df))
416415
self.assertTrue(has_horizontally_truncated_repr(df))
417416
else:
418417
self.assertFalse(has_horizontally_truncated_repr(df))

pandas/tests/test_frame.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4963,7 +4963,7 @@ def test_arith_flex_frame(self):
49634963
assert_frame_equal(result, exp)
49644964
_check_mixed_int(result, dtype = dtype)
49654965
except:
4966-
print("Failing operation %r" % op)
4966+
com.pprint_thing("Failing operation %r" % op)
49674967
raise
49684968

49694969
# ndim >= 3
@@ -5792,7 +5792,6 @@ def make_dtnat_arr(n,nnat=None):
57925792
base = int((chunksize// ncols or 1) or 1)
57935793
for nrows in [10,N-2,N-1,N,N+1,N+2,2*N-2,2*N-1,2*N,2*N+1,2*N+2,
57945794
base-1,base,base+1]:
5795-
#print( nrows,ncols)
57965795
_do_test(mkdf(nrows, ncols),path)
57975796

57985797
for nrows in [10,N-2,N-1,N,N+1,N+2]:
@@ -5814,7 +5813,6 @@ def make_dtnat_arr(n,nnat=None):
58145813
base = int(chunksize//ncols)
58155814
for nrows in [10,N-2,N-1,N,N+1,N+2,2*N-2,2*N-1,2*N,2*N+1,2*N+2,
58165815
base-1,base,base+1]:
5817-
#print(nrows, ncols)
58185816
_do_test(mkdf(nrows, ncols,r_idx_nlevels=2),path,rnlvl=2)
58195817
_do_test(mkdf(nrows, ncols,c_idx_nlevels=2),path,cnlvl=2)
58205818
_do_test(mkdf(nrows, ncols,r_idx_nlevels=2,c_idx_nlevels=2),
@@ -10952,14 +10950,14 @@ def test_mode(self):
1095210950

1095310951
# outputs in sorted order
1095410952
df["C"] = list(reversed(df["C"]))
10955-
print(df["C"])
10956-
print(df["C"].mode())
10953+
com.pprint_thing(df["C"])
10954+
com.pprint_thing(df["C"].mode())
1095710955
a, b = (df[["A", "B", "C"]].mode(),
1095810956
pd.DataFrame({"A": [12, np.nan],
1095910957
"B": [10, np.nan],
1096010958
"C": [8, 9]}))
10961-
print(a)
10962-
print(b)
10959+
com.pprint_thing(a)
10960+
com.pprint_thing(b)
1096310961
assert_frame_equal(a, b)
1096410962
# should work with heterogeneous types
1096510963
df = pd.DataFrame({"A": range(6),
@@ -12981,7 +12979,6 @@ def to_series(mi, level):
1298112979
if isinstance(v, Index):
1298212980
assert v.is_(expected[k])
1298312981
elif isinstance(v, Series):
12984-
#print(k)
1298512982
tm.assert_series_equal(v, expected[k])
1298612983
else:
1298712984
raise AssertionError("object must be a Series or Index")

pandas/tests/test_generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_nonzero(self):
163163

164164
def f():
165165
if obj1:
166-
print("this works and shouldn't")
166+
com.pprint_thing("this works and shouldn't")
167167
self.assertRaises(ValueError, f)
168168
self.assertRaises(ValueError, lambda : obj1 and obj2)
169169
self.assertRaises(ValueError, lambda : obj1 or obj2)

pandas/tests/test_groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ def test_agg_item_by_item_raise_typeerror(self):
730730
df = DataFrame(randint(10, size=(20, 10)))
731731

732732
def raiseException(df):
733-
print('----------------------------------------')
734-
print(df.to_string())
733+
com.pprint_thing('----------------------------------------')
734+
com.pprint_thing(df.to_string())
735735
raise TypeError
736736

737737
self.assertRaises(TypeError, df.groupby(0).agg,

pandas/tests/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _print(result, error = None):
162162
error = str(error)
163163
v = "%-16.16s [%-16.16s]: [typ->%-8.8s,obj->%-8.8s,key1->(%-4.4s),key2->(%-4.4s),axis->%s] %s" % (name,result,t,o,method1,method2,a,error or '')
164164
if _verbose:
165-
print(v)
165+
com.pprint_thing(v)
166166

167167
try:
168168

pandas/tests/test_panel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,13 @@ def check_op(op, name):
330330
try:
331331
check_op(getattr(operator, op), op)
332332
except:
333-
print("Failing operation: %r" % op)
333+
com.pprint_thing("Failing operation: %r" % op)
334334
raise
335335
if compat.PY3:
336336
try:
337337
check_op(operator.truediv, 'div')
338338
except:
339-
print("Failing operation: %r" % name)
339+
com.pprint_thing("Failing operation: %r" % name)
340340
raise
341341

342342
def test_combinePanel(self):
@@ -1928,8 +1928,8 @@ def check_drop(drop_val, axis_number, aliases, expected):
19281928
actual = panel.drop(drop_val, axis=alias)
19291929
assert_panel_equal(actual, expected)
19301930
except AssertionError:
1931-
print("Failed with axis_number %d and aliases: %s" %
1932-
(axis_number, aliases))
1931+
com.pprint_thing("Failed with axis_number %d and aliases: %s" %
1932+
(axis_number, aliases))
19331933
raise
19341934
# Items
19351935
expected = Panel({"One": df})

pandas/tests/test_series.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pandas.core.index import MultiIndex
1919
from pandas.core.indexing import IndexingError
2020
from pandas.tseries.index import Timestamp, DatetimeIndex
21+
import pandas.core.common as com
2122
import pandas.core.config as cf
2223
import pandas.lib as lib
2324

@@ -73,7 +74,7 @@ def test_copy_index_name_checking(self):
7374
self.assertIs(self.ts, self.ts)
7475
cp = self.ts.copy()
7576
cp.index.name = 'foo'
76-
print(self.ts.index.name)
77+
com.pprint_thing(self.ts.index.name)
7778
self.assertIsNone(self.ts.index.name)
7879

7980
def test_append_preserve_name(self):
@@ -2744,7 +2745,7 @@ def run_ops(ops, get_ser, test_ser):
27442745
if op is not None:
27452746
self.assertRaises(TypeError, op, test_ser)
27462747
except:
2747-
print("Failed on op %r" % op)
2748+
com.pprint_thing("Failed on op %r" % op)
27482749
raise
27492750
### timedelta64 ###
27502751
td1 = Series([timedelta(minutes=5,seconds=3)]*3)

0 commit comments

Comments
 (0)