Skip to content

More unicode fixes #1994

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 9 commits into from Oct 1, 2012
2 changes: 1 addition & 1 deletion pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def to_latex(self, force_unicode=False, column_format=None):
if column_format is None:
column_format = '|l|%s|' % '|'.join('c' for _ in strcols)
else:
assert isinstance(column_format, str)
assert isinstance(column_format, basestring)

self.buf.write('\\begin{tabular}{%s}\n' % column_format)
self.buf.write('\\hline\n')
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ def info(self, verbose=True, buf=None):
counts = self.count()
assert(len(cols) == len(counts))
for col, count in counts.iteritems():
if not isinstance(col, (unicode, str)):
if not isinstance(col, basestring):
col = str(col)
lines.append(_put_str(col, space) +
'%d non-null values' % count)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _read(cls, filepath_or_buffer, kwds):
if skipfooter is not None:
kwds['skip_footer'] = skipfooter

if isinstance(filepath_or_buffer, str) and _is_url(filepath_or_buffer):
if isinstance(filepath_or_buffer, basestring) and _is_url(filepath_or_buffer):
from urllib2 import urlopen
filepath_or_buffer = urlopen(filepath_or_buffer)
if py3compat.PY3: # pragma: no cover
Expand Down
7 changes: 6 additions & 1 deletion pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ def test_empty_string(self):


def test_read_csv(self):
pass
if not py3compat.PY3:
fname=u"file://"+unicode(self.csv1)
try:
df1 = read_csv(fname, index_col=0, parse_dates=True)
except IOError:
assert(False), "read_csv should accept unicode objects as urls"

def test_dialect(self):
data = """\
Expand Down
4 changes: 2 additions & 2 deletions pandas/tseries/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _to_ordinalf(tm):
return tot_sec

def time2num(d):
if isinstance(d, str):
if isinstance(d, basestring):
parsed = tools.to_datetime(d)
if not isinstance(parsed, datetime):
raise ValueError('Could not parse time %s' % d)
Expand Down Expand Up @@ -150,7 +150,7 @@ def try_parse(values):
return dates.date2num(values)
elif (com.is_integer(values) or com.is_float(values)):
return values
elif isinstance(values, str):
elif isinstance(values, basestring):
return try_parse(values)
elif isinstance(values, (list, tuple, np.ndarray)):
if not isinstance(values, np.ndarray):
Expand Down
28 changes: 28 additions & 0 deletions pandas/tseries/tests/test_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from datetime import datetime, time, timedelta
import sys
import os
import unittest

import nose

import numpy as np

import pandas.tseries.converter as converter

def test_timtetonum_accepts_unicode():
assert(converter.time2num("00:01")==converter.time2num(u"00:01"))

class TestDateTimeConverter(unittest.TestCase):

def setUp(self):
self.dtc = converter.DatetimeConverter()

def test_convert_accepts_unicode(self):
r1 = self.dtc.convert("12:22",None,None)
r2 = self.dtc.convert(u"12:22",None,None)
assert(r1==r2), "DatetimeConverter.convert should accept unicode"

if __name__ == '__main__':
import nose
nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
exit=False)
2 changes: 1 addition & 1 deletion pandas/tseries/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _infer(a, b):


def _maybe_get_tz(tz):
if isinstance(tz, (str, unicode)):
if isinstance(tz, basestring):
import pytz
tz = pytz.timezone(tz)
if com.is_integer(tz):
Expand Down