From 9a357af33150bf89781c1d54c53742ae824dcf99 Mon Sep 17 00:00:00 2001 From: jreback Date: Tue, 27 May 2014 12:24:54 -0400 Subject: [PATCH] TST/CLN: remove prints (esp of unicode), replacing with com.pprint_thing (GH7247) --- pandas/io/tests/test_data.py | 4 ---- pandas/io/tests/test_pytables.py | 28 ++++++++++++++-------------- pandas/tests/test_expressions.py | 6 +++--- pandas/tests/test_format.py | 5 ++--- pandas/tests/test_frame.py | 13 +++++-------- pandas/tests/test_generic.py | 2 +- pandas/tests/test_groupby.py | 4 ++-- pandas/tests/test_indexing.py | 2 +- pandas/tests/test_panel.py | 8 ++++---- pandas/tests/test_series.py | 5 +++-- 10 files changed, 35 insertions(+), 42 deletions(-) diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index a413893309582..cf7c906a273b1 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -318,7 +318,6 @@ def tearDownClass(cls): @network def test_get_options_data_warning(self): with assert_produces_warning(): - print('month: {0}, year: {1}'.format(self.month, self.year)) try: self.aapl.get_options_data(month=self.month, year=self.year) except RemoteDataError as e: @@ -327,7 +326,6 @@ def test_get_options_data_warning(self): @network def test_get_near_stock_price_warning(self): with assert_produces_warning(): - print('month: {0}, year: {1}'.format(self.month, self.year)) try: calls_near, puts_near = self.aapl.get_near_stock_price(call=True, put=True, @@ -339,7 +337,6 @@ def test_get_near_stock_price_warning(self): @network def test_get_call_data_warning(self): with assert_produces_warning(): - print('month: {0}, year: {1}'.format(self.month, self.year)) try: self.aapl.get_call_data(month=self.month, year=self.year) except RemoteDataError as e: @@ -348,7 +345,6 @@ def test_get_call_data_warning(self): @network def test_get_put_data_warning(self): with assert_produces_warning(): - print('month: {0}, year: {1}'.format(self.month, self.year)) try: self.aapl.get_put_data(month=self.month, year=self.year) except RemoteDataError as e: diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 9a5b0d7fc60ca..77555ad81a45b 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -1506,7 +1506,7 @@ def test_big_table_frame(self): recons = store.select('df') assert isinstance(recons, DataFrame) - print("\nbig_table frame [%s] -> %5.2f" % (rows, time.time() - x)) + com.pprint_thing("\nbig_table frame [%s] -> %5.2f" % (rows, time.time() - x)) def test_big_table2_frame(self): # this is a really big table: 1m rows x 60 float columns, 20 string, 20 datetime @@ -1514,7 +1514,7 @@ def test_big_table2_frame(self): raise nose.SkipTest('no big table2 frame') # create and write a big table - print("\nbig_table2 start") + com.pprint_thing("\nbig_table2 start") import time start_time = time.time() df = DataFrame(np.random.randn(1000 * 1000, 60), index=range(int( @@ -1524,7 +1524,7 @@ def test_big_table2_frame(self): for x in range(20): df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0) - print("\nbig_table2 frame (creation of df) [rows->%s] -> %5.2f" + com.pprint_thing("\nbig_table2 frame (creation of df) [rows->%s] -> %5.2f" % (len(df.index), time.time() - start_time)) def f(chunksize): @@ -1535,15 +1535,15 @@ def f(chunksize): for c in [10000, 50000, 250000]: start_time = time.time() - print("big_table2 frame [chunk->%s]" % c) + com.pprint_thing("big_table2 frame [chunk->%s]" % c) rows = f(c) - print("big_table2 frame [rows->%s,chunk->%s] -> %5.2f" - % (rows, c, time.time() - start_time)) + com.pprint_thing("big_table2 frame [rows->%s,chunk->%s] -> %5.2f" + % (rows, c, time.time() - start_time)) def test_big_put_frame(self): raise nose.SkipTest('no big put frame') - print("\nbig_put start") + com.pprint_thing("\nbig_put start") import time start_time = time.time() df = DataFrame(np.random.randn(1000 * 1000, 60), index=range(int( @@ -1553,7 +1553,7 @@ def test_big_put_frame(self): for x in range(20): df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0) - print("\nbig_put frame (creation of df) [rows->%s] -> %5.2f" + com.pprint_thing("\nbig_put frame (creation of df) [rows->%s] -> %5.2f" % (len(df.index), time.time() - start_time)) with ensure_clean_store(self.path, mode='w') as store: @@ -1561,8 +1561,8 @@ def test_big_put_frame(self): store = HDFStore(self.path, mode='w') store.put('df', df) - print(df.get_dtype_counts()) - print("big_put frame [shape->%s] -> %5.2f" + com.pprint_thing(df.get_dtype_counts()) + com.pprint_thing("big_put frame [shape->%s] -> %5.2f" % (df.shape, time.time() - start_time)) def test_big_table_panel(self): @@ -1588,7 +1588,7 @@ def test_big_table_panel(self): recons = store.select('wp') assert isinstance(recons, Panel) - print("\nbig_table panel [%s] -> %5.2f" % (rows, time.time() - x)) + com.pprint_thing("\nbig_table panel [%s] -> %5.2f" % (rows, time.time() - x)) def test_append_diff_item_order(self): @@ -3538,9 +3538,9 @@ def test_string_select(self): expected = df[df.x != 'none'] assert_frame_equal(result,expected) except Exception as detail: - print("[{0}]".format(detail)) - print(store) - print(expected) + com.pprint_thing("[{0}]".format(detail)) + com.pprint_thing(store) + com.pprint_thing(expected) df2 = df.copy() df2.loc[df2.x=='','x'] = np.nan diff --git a/pandas/tests/test_expressions.py b/pandas/tests/test_expressions.py index 09fc991dc1726..777acdf30f1a0 100644 --- a/pandas/tests/test_expressions.py +++ b/pandas/tests/test_expressions.py @@ -91,7 +91,7 @@ def run_arithmetic_test(self, df, other, assert_func, check_dtype=False, assert expected.dtype.kind == 'f' assert_func(expected, result) except Exception: - print("Failed test with operator %r" % op.__name__) + com.pprint_thing("Failed test with operator %r" % op.__name__) raise def test_integer_arithmetic(self): @@ -131,8 +131,8 @@ def run_binary_test(self, df, other, assert_func, assert not used_numexpr, "Used numexpr unexpectedly." assert_func(expected, result) except Exception: - print("Failed test with operation %r" % arith) - print("test_flex was %r" % test_flex) + com.pprint_thing("Failed test with operation %r" % arith) + com.pprint_thing("test_flex was %r" % test_flex) raise def run_frame(self, df, other, binary_comp=None, run_binary=True, diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index dddfcc976c4a6..8e405dc98f3da 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -18,6 +18,7 @@ import pandas.core.format as fmt import pandas.util.testing as tm +import pandas.core.common as com from pandas.util.terminal import get_terminal_size import pandas import pandas.tslib as tslib @@ -288,7 +289,7 @@ def mkframe(n): df = mkframe((term_width // 7) - 2) self.assertFalse(has_expanded_repr(df)) df = mkframe((term_width // 7) + 2) - print( df._repr_fits_horizontal_()) + com.pprint_thing(df._repr_fits_horizontal_()) self.assertTrue(has_expanded_repr(df)) def test_to_string_repr_unicode(self): @@ -411,8 +412,6 @@ def test_to_string_truncate_indices(self): self.assertFalse(has_vertically_truncated_repr(df)) with option_context("display.max_columns", 15): if w == 20: - print(df) - print(repr(df)) self.assertTrue(has_horizontally_truncated_repr(df)) else: self.assertFalse(has_horizontally_truncated_repr(df)) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 7d040b2ede0f7..4e5b00a6db765 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -4963,7 +4963,7 @@ def test_arith_flex_frame(self): assert_frame_equal(result, exp) _check_mixed_int(result, dtype = dtype) except: - print("Failing operation %r" % op) + com.pprint_thing("Failing operation %r" % op) raise # ndim >= 3 @@ -5792,7 +5792,6 @@ def make_dtnat_arr(n,nnat=None): base = int((chunksize// ncols or 1) or 1) 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, base-1,base,base+1]: - #print( nrows,ncols) _do_test(mkdf(nrows, ncols),path) for nrows in [10,N-2,N-1,N,N+1,N+2]: @@ -5814,7 +5813,6 @@ def make_dtnat_arr(n,nnat=None): base = int(chunksize//ncols) 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, base-1,base,base+1]: - #print(nrows, ncols) _do_test(mkdf(nrows, ncols,r_idx_nlevels=2),path,rnlvl=2) _do_test(mkdf(nrows, ncols,c_idx_nlevels=2),path,cnlvl=2) _do_test(mkdf(nrows, ncols,r_idx_nlevels=2,c_idx_nlevels=2), @@ -10952,14 +10950,14 @@ def test_mode(self): # outputs in sorted order df["C"] = list(reversed(df["C"])) - print(df["C"]) - print(df["C"].mode()) + com.pprint_thing(df["C"]) + com.pprint_thing(df["C"].mode()) a, b = (df[["A", "B", "C"]].mode(), pd.DataFrame({"A": [12, np.nan], "B": [10, np.nan], "C": [8, 9]})) - print(a) - print(b) + com.pprint_thing(a) + com.pprint_thing(b) assert_frame_equal(a, b) # should work with heterogeneous types df = pd.DataFrame({"A": range(6), @@ -12981,7 +12979,6 @@ def to_series(mi, level): if isinstance(v, Index): assert v.is_(expected[k]) elif isinstance(v, Series): - #print(k) tm.assert_series_equal(v, expected[k]) else: raise AssertionError("object must be a Series or Index") diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py index d85e5facfad01..5f07acf25582f 100644 --- a/pandas/tests/test_generic.py +++ b/pandas/tests/test_generic.py @@ -163,7 +163,7 @@ def test_nonzero(self): def f(): if obj1: - print("this works and shouldn't") + com.pprint_thing("this works and shouldn't") self.assertRaises(ValueError, f) self.assertRaises(ValueError, lambda : obj1 and obj2) self.assertRaises(ValueError, lambda : obj1 or obj2) diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 4310a5947036f..028334afbd62c 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -730,8 +730,8 @@ def test_agg_item_by_item_raise_typeerror(self): df = DataFrame(randint(10, size=(20, 10))) def raiseException(df): - print('----------------------------------------') - print(df.to_string()) + com.pprint_thing('----------------------------------------') + com.pprint_thing(df.to_string()) raise TypeError self.assertRaises(TypeError, df.groupby(0).agg, diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 14f2ee6222238..b61b1ab925396 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -162,7 +162,7 @@ def _print(result, error = None): error = str(error) 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 '') if _verbose: - print(v) + com.pprint_thing(v) try: diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 2f539bcc6d128..2ed24832c3270 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -330,13 +330,13 @@ def check_op(op, name): try: check_op(getattr(operator, op), op) except: - print("Failing operation: %r" % op) + com.pprint_thing("Failing operation: %r" % op) raise if compat.PY3: try: check_op(operator.truediv, 'div') except: - print("Failing operation: %r" % name) + com.pprint_thing("Failing operation: %r" % name) raise def test_combinePanel(self): @@ -1928,8 +1928,8 @@ def check_drop(drop_val, axis_number, aliases, expected): actual = panel.drop(drop_val, axis=alias) assert_panel_equal(actual, expected) except AssertionError: - print("Failed with axis_number %d and aliases: %s" % - (axis_number, aliases)) + com.pprint_thing("Failed with axis_number %d and aliases: %s" % + (axis_number, aliases)) raise # Items expected = Panel({"One": df}) diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index b9db6e8adb634..6c732fe352d6a 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -18,6 +18,7 @@ from pandas.core.index import MultiIndex from pandas.core.indexing import IndexingError from pandas.tseries.index import Timestamp, DatetimeIndex +import pandas.core.common as com import pandas.core.config as cf import pandas.lib as lib @@ -73,7 +74,7 @@ def test_copy_index_name_checking(self): self.assertIs(self.ts, self.ts) cp = self.ts.copy() cp.index.name = 'foo' - print(self.ts.index.name) + com.pprint_thing(self.ts.index.name) self.assertIsNone(self.ts.index.name) def test_append_preserve_name(self): @@ -2744,7 +2745,7 @@ def run_ops(ops, get_ser, test_ser): if op is not None: self.assertRaises(TypeError, op, test_ser) except: - print("Failed on op %r" % op) + com.pprint_thing("Failed on op %r" % op) raise ### timedelta64 ### td1 = Series([timedelta(minutes=5,seconds=3)]*3)