Skip to content

Commit 8def938

Browse files
committed
FIX py3ing some print statements
1 parent 40064ec commit 8def938

22 files changed

+63
-52
lines changed

examples/regressions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def makeSeries():
3131

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

34-
print model
34+
print (model)
3535

3636
#-------------------------------------------------------------------------------
3737
# Panel regression
@@ -48,4 +48,4 @@ def makeSeries():
4848

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

51-
print panelModel
51+
print (panelModel)

pandas/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
__docformat__ = 'restructuredtext'
44

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

1118
from datetime import datetime
1219
import numpy as np

pandas/core/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _describe_option(pat='', _print_desc=True):
154154
s += _build_option_description(k)
155155

156156
if _print_desc:
157-
print s
157+
print (s)
158158
else:
159159
return s
160160

@@ -631,7 +631,7 @@ def pp(name, ks):
631631
ls += pp(k, ks)
632632
s = '\n'.join(ls)
633633
if _print:
634-
print s
634+
print (s)
635635
else:
636636
return s
637637

pandas/core/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,4 +1899,4 @@ def _binify(cols, line_width):
18991899
1134250., 1219550., 855736.85, 1042615.4286,
19001900
722621.3043, 698167.1818, 803750.])
19011901
fmt = FloatArrayFormatter(arr, digits=7)
1902-
print fmt.get_result()
1902+
print (fmt.get_result())

pandas/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ def aggregate(self, func_or_funcs, *args, **kwargs):
14201420
ret = Series(result, index=index)
14211421

14221422
if not self.as_index: # pragma: no cover
1423-
print 'Warning, ignoring as_index=True'
1423+
print ('Warning, ignoring as_index=True')
14241424

14251425
return ret
14261426

pandas/io/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def process_flags(flags=[]):
5555
try:
5656
FLAGS(flags)
5757
except gflags.FlagsError, e:
58-
print '%s\nUsage: %s ARGS\n%s' % (e, str(flags), FLAGS)
58+
print ('%s\nUsage: %s ARGS\n%s' % (e, str(flags), FLAGS))
5959
sys.exit(1)
6060

6161
# Set the logging according to the command-line flag.

pandas/io/data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_quote_yahoo(symbols):
115115
lines = urllib2.urlopen(urlStr).readlines()
116116
except Exception, e:
117117
s = "Failed to download:\n{0}".format(e)
118-
print s
118+
print (s)
119119
return None
120120

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

469469
if(name is None):
470-
print "Need to provide a name"
470+
print ("Need to provide a name")
471471
return None
472472

473473
fred_URL = "http://research.stlouisfed.org/fred2/series/"

pandas/io/parsers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def _clean_options(self, options, engine):
508508
sep = options['delimiter']
509509
if (sep is None and not options['delim_whitespace']):
510510
if engine == 'c':
511-
print 'Using Python parser to sniff delimiter'
511+
print ('Using Python parser to sniff delimiter')
512512
engine = 'python'
513513
elif sep is not None and len(sep) > 1:
514514
# wait until regex engine integrated
@@ -867,7 +867,7 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
867867
coerce_type)
868868
result[c] = cvals
869869
if verbose and na_count:
870-
print 'Filled %d NA values in column %s' % (na_count, str(c))
870+
print ('Filled %d NA values in column %s' % (na_count, str(c)))
871871
return result
872872

873873
def _convert_types(self, values, na_values, try_num_bool=True):

pandas/io/pytables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def open(self, mode='a', warn=True):
386386
self._handle = h5_open(self._path, self._mode)
387387
except IOError, e: # pragma: no cover
388388
if 'can not be written' in str(e):
389-
print 'Opening %s in read-only mode' % self._path
389+
print ('Opening %s in read-only mode' % self._path)
390390
self._handle = h5_open(self._path, 'r')
391391
else:
392392
raise

pandas/io/sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def execute(sql, con, retry=True, cur=None, params=None):
5151
except Exception: # pragma: no cover
5252
pass
5353

54-
print 'Error on sql %s' % sql
54+
print ('Error on sql %s' % sql)
5555
raise
5656

5757

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

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

129129
traceback.print_exc()
130130
if retry:
131-
print 'Looks like your connection failed, reconnecting...'
131+
print ('Looks like your connection failed, reconnecting...')
132132
return uquery(sql, con, retry=False)
133133
return result
134134

pandas/io/tests/test_html.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def test_to_html_compat(self):
8686
out = df.to_html()
8787
res = self.run_read_html(out, attrs={'class': 'dataframe'},
8888
index_col=0)[0]
89-
print df.dtypes
90-
print res.dtypes
89+
print (df.dtypes)
90+
print (res.dtypes)
9191
assert_frame_equal(res, df)
9292

9393
@network
@@ -125,7 +125,7 @@ def test_spam(self):
125125
df2 = self.run_read_html(self.spam_data, 'Unit', infer_types=False)
126126

127127
assert_framelist_equal(df1, df2)
128-
print df1[0]
128+
print (df1[0])
129129

130130
self.assertEqual(df1[0].ix[0, 0], 'Proximates')
131131
self.assertEqual(df1[0].columns[0], 'Nutrient')

pandas/io/tests/test_pytables.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -987,15 +987,15 @@ def test_big_table_frame(self):
987987
rows = store.root.df.table.nrows
988988
recons = store.select('df')
989989

990-
print "\nbig_table frame [%s] -> %5.2f" % (rows, time.time() - x)
990+
print ("\nbig_table frame [%s] -> %5.2f" % (rows, time.time() - x))
991991

992992
def test_big_table2_frame(self):
993993
# this is a really big table: 1m rows x 60 float columns, 20 string, 20 datetime
994994
# columns
995995
raise nose.SkipTest('no big table2 frame')
996996

997997
# create and write a big table
998-
print "\nbig_table2 start"
998+
print ("\nbig_table2 start")
999999
import time
10001000
start_time = time.time()
10011001
df = DataFrame(np.random.randn(1000 * 1000, 60), index=xrange(int(
@@ -1005,7 +1005,8 @@ def test_big_table2_frame(self):
10051005
for x in xrange(20):
10061006
df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0)
10071007

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

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

10161017
for c in [10000, 50000, 250000]:
10171018
start_time = time.time()
1018-
print "big_table2 frame [chunk->%s]" % c
1019+
print ("big_table2 frame [chunk->%s]" % c)
10191020
rows = f(c)
1020-
print "big_table2 frame [rows->%s,chunk->%s] -> %5.2f" % (rows, c, time.time() - start_time)
1021+
print ("big_table2 frame [rows->%s,chunk->%s] -> %5.2f"
1022+
% (rows, c, time.time() - start_time))
10211023

10221024
def test_big_put_frame(self):
10231025
raise nose.SkipTest('no big put frame')
10241026

1025-
print "\nbig_put start"
1027+
print ("\nbig_put start")
10261028
import time
10271029
start_time = time.time()
10281030
df = DataFrame(np.random.randn(1000 * 1000, 60), index=xrange(int(
@@ -1032,15 +1034,17 @@ def test_big_put_frame(self):
10321034
for x in xrange(20):
10331035
df['datetime%03d' % x] = datetime.datetime(2001, 1, 2, 0, 0)
10341036

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

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

1042-
print df.get_dtype_counts()
1043-
print "big_put frame [shape->%s] -> %5.2f" % (df.shape, time.time() - start_time)
1045+
print (df.get_dtype_counts())
1046+
print ("big_put frame [shape->%s] -> %5.2f"
1047+
% (df.shape, time.time() - start_time))
10441048

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

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

10691073
def test_append_diff_item_order(self):
10701074

@@ -2461,10 +2465,10 @@ def test_select_as_multiple(self):
24612465
expected = expected[5:]
24622466
tm.assert_frame_equal(result, expected)
24632467
except (Exception), detail:
2464-
print "error in select_as_multiple %s" % str(detail)
2465-
print "store: ", store
2466-
print "df1: ", df1
2467-
print "df2: ", df2
2468+
print ("error in select_as_multiple %s" % str(detail))
2469+
print ("store: %s" % store)
2470+
print ("df1: %s" % df1)
2471+
print ("df2: %s" % df2)
24682472

24692473

24702474
# test excpection for diff rows

pandas/io/wb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ def download(country=['MX', 'CA', 'US'], indicator=['GDPPCKD', 'GDPPCKN'],
6565
bad_indicators.append(ind)
6666
# Warn
6767
if len(bad_indicators) > 0:
68-
print 'Failed to obtain indicator(s): ' + '; '.join(bad_indicators)
69-
print 'The data may still be available for download at http://data.worldbank.org'
68+
print ('Failed to obtain indicator(s): %s' % '; '.join(bad_indicators))
69+
print ('The data may still be available for download at http://data.worldbank.org')
7070
if len(bad_countries) > 0:
71-
print 'Invalid ISO-2 codes: ' + ' '.join(bad_countries)
71+
print ('Invalid ISO-2 codes: %s' % ' '.join(bad_countries))
7272
# Merge WDI series
7373
if len(data) > 0:
7474
out = reduce(lambda x, y: x.merge(y, how='outer'), data)

pandas/rpy/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _convert_array(obj):
7373
major_axis=name_list[0],
7474
minor_axis=name_list[1])
7575
else:
76-
print 'Cannot handle dim=%d' % len(dim)
76+
print ('Cannot handle dim=%d' % len(dim))
7777
else:
7878
return arr
7979

pandas/stats/plm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, y, x, weights=None, intercept=True, nw_lags=None,
5656

5757
def log(self, msg):
5858
if self._verbose: # pragma: no cover
59-
print msg
59+
print (msg)
6060

6161
def _prepare_data(self):
6262
"""Cleans and stacks input data into DataFrame objects

pandas/stats/tests/test_var.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def beta(self):
124124
return rpy.convert_robj(r.coef(self._estimate))
125125

126126
def summary(self, equation=None):
127-
print r.summary(self._estimate, equation=equation)
127+
print (r.summary(self._estimate, equation=equation))
128128

129129
def output(self):
130-
print self._estimate
130+
print (self._estimate)
131131

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

146146
def data_summary(self):
147-
print r.summary(self.rdata)
147+
print (r.summary(self.rdata))
148148

149149

150150
class TestVAR(TestCase):

pandas/tests/test_format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ def test_to_string_buffer_all_unicode(self):
337337
empty = DataFrame({u'c/\u03c3': Series()})
338338
nonempty = DataFrame({u'c/\u03c3': Series([1, 2, 3])})
339339

340-
print >>buf, empty
341-
print >>buf, nonempty
340+
print >>buf, empty # TODO py3?
341+
print >>buf, nonempty # TODO py3?
342342

343343
# this should work
344344
buf.getvalue()

pandas/tests/test_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9079,7 +9079,7 @@ def _check_stat_op(self, name, alternative, frame=None, has_skipna=True,
90799079
if not ('max' in name or 'min' in name or 'count' in name):
90809080
df = DataFrame({'b': date_range('1/1/2001', periods=2)})
90819081
_f = getattr(df, name)
9082-
print df
9082+
print (df)
90839083
self.assertFalse(len(_f()))
90849084

90859085
df['a'] = range(len(df))

pandas/tests/test_groupby.py

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

501501
def raiseException(df):
502-
print '----------------------------------------'
503-
print df.to_string()
502+
print ('----------------------------------------')
503+
print (df.to_string())
504504
raise TypeError
505505

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

pandas/tseries/resample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def resample(self, obj):
8585
offset = to_offset(self.freq)
8686
if offset.n > 1:
8787
if self.kind == 'period': # pragma: no cover
88-
print 'Warning: multiple of frequency -> timestamps'
88+
print ('Warning: multiple of frequency -> timestamps')
8989
# Cannot have multiple of periods, convert to timestamp
9090
self.kind = 'timestamp'
9191

pandas/tseries/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
raise Exception('dateutil 2.0 incompatible with Python 2.x, you must '
2121
'install version 1.5 or 2.1+!')
2222
except ImportError: # pragma: no cover
23-
print 'Please install python-dateutil via easy_install or some method!'
23+
print ('Please install python-dateutil via easy_install or some method!')
2424
raise # otherwise a 2nd import won't show the message
2525

2626

pandas/util/terminal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ def ioctl_GWINSZ(fd):
117117

118118
if __name__ == "__main__":
119119
sizex, sizey = get_terminal_size()
120-
print 'width =', sizex, 'height =', sizey
120+
print ('width = %s height = %s' % (sizex, sizey))

0 commit comments

Comments
 (0)