Skip to content

TST/CLN: remove prints (esp of unicode), replacing with com.pprint_thing (GH7247) #7248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pandas/io/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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:
Expand Down
28 changes: 14 additions & 14 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,15 +1506,15 @@ 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
# columns
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(
Expand All @@ -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):
Expand All @@ -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(
Expand All @@ -1553,16 +1553,16 @@ 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:
start_time = time.time()
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):
Expand All @@ -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):

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand Down
13 changes: 5 additions & 8 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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})
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down