Skip to content

FIX py3ing some print statements #3821

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 2 commits into from
Jun 21, 2013
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: 2 additions & 2 deletions examples/regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def makeSeries():

model = ols(y=Y, x=X)

print model
print (model)

#-------------------------------------------------------------------------------
# Panel regression
Expand All @@ -48,4 +48,4 @@ def makeSeries():

model = ols(y=Y, x=data)

print panelModel
print (panelModel)
15 changes: 11 additions & 4 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
__docformat__ = 'restructuredtext'

try:
from pandas import hashtable, tslib, lib
except ImportError as e: # pragma: no cover
module = str(e).lstrip('cannot import name ') # hack but overkill to use re
raise ImportError("C extensions: {0} not built".format(module))
from . import hashtable, tslib, lib
except Exception: # pragma: no cover
import sys
e = sys.exc_info()[1] # Py25 and Py3 current exception syntax conflict
print (e)
if 'No module named lib' in str(e):
raise ImportError('C extensions not built: if you installed already '
'verify that you are not importing from the source '
'directory')
else:
raise

from datetime import datetime
import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _describe_option(pat='', _print_desc=True):
s += _build_option_description(k)

if _print_desc:
print s
print (s)
else:
return s

Expand Down Expand Up @@ -631,7 +631,7 @@ def pp(name, ks):
ls += pp(k, ks)
s = '\n'.join(ls)
if _print:
print s
print (s)
else:
return s

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,4 +1899,4 @@ def _binify(cols, line_width):
1134250., 1219550., 855736.85, 1042615.4286,
722621.3043, 698167.1818, 803750.])
fmt = FloatArrayFormatter(arr, digits=7)
print fmt.get_result()
print (fmt.get_result())
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ def aggregate(self, func_or_funcs, *args, **kwargs):
ret = Series(result, index=index)

if not self.as_index: # pragma: no cover
print 'Warning, ignoring as_index=True'
print ('Warning, ignoring as_index=True')

return ret

Expand Down
2 changes: 1 addition & 1 deletion pandas/io/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def process_flags(flags=[]):
try:
FLAGS(flags)
except gflags.FlagsError, e:
print '%s\nUsage: %s ARGS\n%s' % (e, str(flags), FLAGS)
print ('%s\nUsage: %s ARGS\n%s' % (e, str(flags), FLAGS))
sys.exit(1)

# Set the logging according to the command-line flag.
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_quote_yahoo(symbols):
lines = urllib2.urlopen(urlStr).readlines()
except Exception, e:
s = "Failed to download:\n{0}".format(e)
print s
print (s)
return None

for line in lines:
Expand Down Expand Up @@ -467,7 +467,7 @@ def get_data_fred(name=None, start=dt.datetime(2010, 1, 1),
start, end = _sanitize_dates(start, end)

if(name is None):
print "Need to provide a name"
print ("Need to provide a name")
return None

fred_URL = "http://research.stlouisfed.org/fred2/series/"
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _clean_options(self, options, engine):
sep = options['delimiter']
if (sep is None and not options['delim_whitespace']):
if engine == 'c':
print 'Using Python parser to sniff delimiter'
print ('Using Python parser to sniff delimiter')
engine = 'python'
elif sep is not None and len(sep) > 1:
# wait until regex engine integrated
Expand Down Expand Up @@ -867,7 +867,7 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
coerce_type)
result[c] = cvals
if verbose and na_count:
print 'Filled %d NA values in column %s' % (na_count, str(c))
print ('Filled %d NA values in column %s' % (na_count, str(c)))
return result

def _convert_types(self, values, na_values, try_num_bool=True):
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def open(self, mode='a', warn=True):
self._handle = h5_open(self._path, self._mode)
except IOError, e: # pragma: no cover
if 'can not be written' in str(e):
print 'Opening %s in read-only mode' % self._path
print ('Opening %s in read-only mode' % self._path)
self._handle = h5_open(self._path, 'r')
else:
raise
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def execute(sql, con, retry=True, cur=None, params=None):
except Exception: # pragma: no cover
pass

print 'Error on sql %s' % sql
print ('Error on sql %s' % sql)
raise


Expand Down Expand Up @@ -94,7 +94,7 @@ def tquery(sql, con=None, cur=None, retry=True):
except Exception, e:
excName = e.__class__.__name__
if excName == 'OperationalError': # pragma: no cover
print 'Failed to commit, may need to restart interpreter'
print ('Failed to commit, may need to restart interpreter')
else:
raise

Expand Down Expand Up @@ -128,7 +128,7 @@ def uquery(sql, con=None, cur=None, retry=True, params=None):

traceback.print_exc()
if retry:
print 'Looks like your connection failed, reconnecting...'
print ('Looks like your connection failed, reconnecting...')
return uquery(sql, con, retry=False)
return result

Expand Down
6 changes: 3 additions & 3 deletions pandas/io/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def test_to_html_compat(self):
out = df.to_html()
res = self.run_read_html(out, attrs={'class': 'dataframe'},
index_col=0)[0]
print df.dtypes
print res.dtypes
print (df.dtypes)
print (res.dtypes)
assert_frame_equal(res, df)

@network
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_spam(self):
df2 = self.run_read_html(self.spam_data, 'Unit', infer_types=False)

assert_framelist_equal(df1, df2)
print df1[0]
print (df1[0])

self.assertEqual(df1[0].ix[0, 0], 'Proximates')
self.assertEqual(df1[0].columns[0], 'Nutrient')
Expand Down
32 changes: 18 additions & 14 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,15 +987,15 @@ def test_big_table_frame(self):
rows = store.root.df.table.nrows
recons = store.select('df')

print "\nbig_table frame [%s] -> %5.2f" % (rows, time.time() - x)
print ("\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"
print ("\nbig_table2 start")
import time
start_time = time.time()
df = DataFrame(np.random.randn(1000 * 1000, 60), index=xrange(int(
Expand All @@ -1005,7 +1005,8 @@ def test_big_table2_frame(self):
for x in xrange(20):
df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0)

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

def f(chunksize):
with ensure_clean(self.path,mode='w') as store:
Expand All @@ -1015,14 +1016,15 @@ def f(chunksize):

for c in [10000, 50000, 250000]:
start_time = time.time()
print "big_table2 frame [chunk->%s]" % c
print ("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)
print ("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"
print ("\nbig_put start")
import time
start_time = time.time()
df = DataFrame(np.random.randn(1000 * 1000, 60), index=xrange(int(
Expand All @@ -1032,15 +1034,17 @@ def test_big_put_frame(self):
for x in xrange(20):
df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0)

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

with ensure_clean(self.path, mode='w') as store:
start_time = time.time()
store = HDFStore(fn, mode='w')
store.put('df', df)

print df.get_dtype_counts()
print "big_put frame [shape->%s] -> %5.2f" % (df.shape, time.time() - start_time)
print (df.get_dtype_counts())
print ("big_put frame [shape->%s] -> %5.2f"
% (df.shape, time.time() - start_time))

def test_big_table_panel(self):
raise nose.SkipTest('no big table panel')
Expand All @@ -1064,7 +1068,7 @@ def test_big_table_panel(self):
rows = store.root.wp.table.nrows
recons = store.select('wp')

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

def test_append_diff_item_order(self):

Expand Down Expand Up @@ -2461,10 +2465,10 @@ def test_select_as_multiple(self):
expected = expected[5:]
tm.assert_frame_equal(result, expected)
except (Exception), detail:
print "error in select_as_multiple %s" % str(detail)
print "store: ", store
print "df1: ", df1
print "df2: ", df2
print ("error in select_as_multiple %s" % str(detail))
print ("store: %s" % store)
print ("df1: %s" % df1)
print ("df2: %s" % df2)


# test excpection for diff rows
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def download(country=['MX', 'CA', 'US'], indicator=['GDPPCKD', 'GDPPCKN'],
bad_indicators.append(ind)
# Warn
if len(bad_indicators) > 0:
print 'Failed to obtain indicator(s): ' + '; '.join(bad_indicators)
print 'The data may still be available for download at http://data.worldbank.org'
print ('Failed to obtain indicator(s): %s' % '; '.join(bad_indicators))
print ('The data may still be available for download at http://data.worldbank.org')
if len(bad_countries) > 0:
print 'Invalid ISO-2 codes: ' + ' '.join(bad_countries)
print ('Invalid ISO-2 codes: %s' % ' '.join(bad_countries))
# Merge WDI series
if len(data) > 0:
out = reduce(lambda x, y: x.merge(y, how='outer'), data)
Expand Down
2 changes: 1 addition & 1 deletion pandas/rpy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _convert_array(obj):
major_axis=name_list[0],
minor_axis=name_list[1])
else:
print 'Cannot handle dim=%d' % len(dim)
print ('Cannot handle dim=%d' % len(dim))
else:
return arr

Expand Down
2 changes: 1 addition & 1 deletion pandas/stats/plm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, y, x, weights=None, intercept=True, nw_lags=None,

def log(self, msg):
if self._verbose: # pragma: no cover
print msg
print (msg)

def _prepare_data(self):
"""Cleans and stacks input data into DataFrame objects
Expand Down
6 changes: 3 additions & 3 deletions pandas/stats/tests/test_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ def beta(self):
return rpy.convert_robj(r.coef(self._estimate))

def summary(self, equation=None):
print r.summary(self._estimate, equation=equation)
print (r.summary(self._estimate, equation=equation))

def output(self):
print self._estimate
print (self._estimate)

def estimate(self):
self._estimate = r.VAR(self.rdata, p=self.p, type=self.type)
Expand All @@ -144,7 +144,7 @@ def serial_test(self, lags_pt=16, type='PT.asymptotic'):
return test

def data_summary(self):
print r.summary(self.rdata)
print (r.summary(self.rdata))


class TestVAR(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9079,7 +9079,7 @@ def _check_stat_op(self, name, alternative, frame=None, has_skipna=True,
if not ('max' in name or 'min' in name or 'count' in name):
df = DataFrame({'b': date_range('1/1/2001', periods=2)})
_f = getattr(df, name)
print df
print (df)
self.assertFalse(len(_f()))

df['a'] = range(len(df))
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 @@ -499,8 +499,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()
print ('----------------------------------------')
print (df.to_string())
raise TypeError

self.assertRaises(TypeError, df.groupby(0).agg,
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def resample(self, obj):
offset = to_offset(self.freq)
if offset.n > 1:
if self.kind == 'period': # pragma: no cover
print 'Warning: multiple of frequency -> timestamps'
print ('Warning: multiple of frequency -> timestamps')
# Cannot have multiple of periods, convert to timestamp
self.kind = 'timestamp'

Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
raise Exception('dateutil 2.0 incompatible with Python 2.x, you must '
'install version 1.5 or 2.1+!')
except ImportError: # pragma: no cover
print 'Please install python-dateutil via easy_install or some method!'
print ('Please install python-dateutil via easy_install or some method!')
raise # otherwise a 2nd import won't show the message


Expand Down
2 changes: 1 addition & 1 deletion pandas/util/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ def ioctl_GWINSZ(fd):

if __name__ == "__main__":
sizex, sizey = get_terminal_size()
print 'width =', sizex, 'height =', sizey
print ('width = %s height = %s' % (sizex, sizey))