diff --git a/examples/regressions.py b/examples/regressions.py index 2d21a0ece58c3..2203165825ccb 100644 --- a/examples/regressions.py +++ b/examples/regressions.py @@ -31,7 +31,7 @@ def makeSeries(): model = ols(y=Y, x=X) -print model +print (model) #------------------------------------------------------------------------------- # Panel regression @@ -48,4 +48,4 @@ def makeSeries(): model = ols(y=Y, x=data) -print panelModel +print (panelModel) diff --git a/pandas/__init__.py b/pandas/__init__.py index 62de9a10e729b..a0edb397c28c1 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -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 diff --git a/pandas/core/config.py b/pandas/core/config.py index e8403164ac1b9..ae7c71d082a89 100644 --- a/pandas/core/config.py +++ b/pandas/core/config.py @@ -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 @@ -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 diff --git a/pandas/core/format.py b/pandas/core/format.py index 40d80e91f0264..b1f7a2a8964b9 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -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()) diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index d15dcc1510577..43def5047197a 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -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 diff --git a/pandas/io/auth.py b/pandas/io/auth.py index 5e64b795b8885..6da497687cf25 100644 --- a/pandas/io/auth.py +++ b/pandas/io/auth.py @@ -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. diff --git a/pandas/io/data.py b/pandas/io/data.py index 8bc3df561cadb..a97c77c207a4c 100644 --- a/pandas/io/data.py +++ b/pandas/io/data.py @@ -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: @@ -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/" diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 054363d8cda06..e9088d68d73fa 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -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 @@ -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): diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 83e46fc949a4d..6cfbfd0f2d60a 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -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 diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 4a1cac8a60e30..68dff479a5015 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -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 @@ -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 @@ -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 diff --git a/pandas/io/tests/test_html.py b/pandas/io/tests/test_html.py index d6086d822ee02..0157729044782 100644 --- a/pandas/io/tests/test_html.py +++ b/pandas/io/tests/test_html.py @@ -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 @@ -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') diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index f7f77698f51f5..f348e1ddce461 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -987,7 +987,7 @@ 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 @@ -995,7 +995,7 @@ def test_big_table2_frame(self): 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( @@ -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: @@ -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( @@ -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') @@ -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): @@ -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 diff --git a/pandas/io/wb.py b/pandas/io/wb.py index 1a2108d069589..579da6bbc4e45 100644 --- a/pandas/io/wb.py +++ b/pandas/io/wb.py @@ -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) diff --git a/pandas/rpy/common.py b/pandas/rpy/common.py index acc562925c925..92adee5bdae57 100644 --- a/pandas/rpy/common.py +++ b/pandas/rpy/common.py @@ -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 diff --git a/pandas/stats/plm.py b/pandas/stats/plm.py index 467ce6a05e1f0..e8c413ec4739c 100644 --- a/pandas/stats/plm.py +++ b/pandas/stats/plm.py @@ -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 diff --git a/pandas/stats/tests/test_var.py b/pandas/stats/tests/test_var.py index 282a794980979..cbaacd0e89b6e 100644 --- a/pandas/stats/tests/test_var.py +++ b/pandas/stats/tests/test_var.py @@ -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) @@ -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): diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 8b32b3a641ebb..dd2fd88945f19 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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)) diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index 6989d3bcae42b..8f60cb8fc6a63 100644 --- a/pandas/tests/test_groupby.py +++ b/pandas/tests/test_groupby.py @@ -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, diff --git a/pandas/tseries/resample.py b/pandas/tseries/resample.py index 4bf0a5bf3182c..9c22ad66d4f2b 100644 --- a/pandas/tseries/resample.py +++ b/pandas/tseries/resample.py @@ -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' diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index 43d44702d2d5e..c39f65f95d99f 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -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 diff --git a/pandas/util/terminal.py b/pandas/util/terminal.py index 7b9ddfbcfc8e6..3b5f893d1a0b3 100644 --- a/pandas/util/terminal.py +++ b/pandas/util/terminal.py @@ -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))