From 16860509f8eda95fc3acfb4a88eb686842c9f424 Mon Sep 17 00:00:00 2001 From: David Stephens Date: Sat, 6 Dec 2014 12:44:13 -0800 Subject: [PATCH] BUG: Datareader index name shows unicode characters --- doc/source/whatsnew/v0.15.2.txt | 1 + doc/source/whatsnew/v0.16.0.txt | 2 ++ pandas/io/data.py | 8 ++++++++ pandas/io/tests/test_data.py | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index 02de919e3f83e..22a89b465ad7d 100644 --- a/doc/source/whatsnew/v0.15.2.txt +++ b/doc/source/whatsnew/v0.15.2.txt @@ -239,3 +239,4 @@ Bug Fixes - Bug where passing a unit to the TimedeltaIndex constructor applied the to nano-second conversion twice. (:issue:`9011`). - Bug in plotting of a period-like array (:issue:`9012`) + diff --git a/doc/source/whatsnew/v0.16.0.txt b/doc/source/whatsnew/v0.16.0.txt index b3ac58a9fb84a..931b8009d8cf0 100644 --- a/doc/source/whatsnew/v0.16.0.txt +++ b/doc/source/whatsnew/v0.16.0.txt @@ -202,3 +202,5 @@ Bug Fixes - Fixed issue in the ``xlsxwriter`` engine where it added a default 'General' format to cells if no other format wass applied. This prevented other row or column formatting being applied. (:issue:`9167`) - Fixes issue with ``index_col=False`` when ``usecols`` is also specified in ``read_csv``. (:issue:`9082`) - Bug where ``wide_to_long`` would modify the input stubnames list (:issue:`9204`) +- Bug in Datareader index name shows unicode characters (:issue:`8967`) + diff --git a/pandas/io/data.py b/pandas/io/data.py index b5cf5f9d9be19..72729d7a189f6 100644 --- a/pandas/io/data.py +++ b/pandas/io/data.py @@ -171,6 +171,14 @@ def _retry_read_url(url, retry_count, pause, name): # return 2 rows for the most recent business day if len(rs) > 2 and rs.index[-1] == rs.index[-2]: # pragma: no cover rs = rs[:-1] + + #Get rid of unicode characters in index name. + try: + rs.index.name = rs.index.name.decode('unicode_escape').encode('ascii', 'ignore') + except AttributeError: + #Python 3 string has no decode method. + rs.index.name = rs.index.name.encode('ascii', 'ignore').decode() + return rs raise IOError("after %d tries, %s did not " diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index 2d6f14c79633a..df6a8fe2005be 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -126,6 +126,12 @@ def test_dtypes(self): assert np.issubdtype(data.High.dtype, np.number) assert np.issubdtype(data.Volume.dtype, np.number) + def test_unicode_date(self): + #GH8967 + data = web.get_data_google('F', start='JAN-01-10', end='JAN-27-13') + self.assertEquals(data.index.name, 'Date') + + class TestYahoo(tm.TestCase): @classmethod def setUpClass(cls):