Skip to content

CLN: let URLError fall through in pandas.io.html._read #4305

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 1 commit into from
Jul 25, 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
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pandas 0.12
of the default datetime.min and datetime.max (respectively), thanks @SleepingPills
- ``read_html`` now raises when no tables are found and BeautifulSoup==4.2.0
is detected (:issue:`4214`)
- ``read_html`` now raises a ``URLError`` instead of catching and raising a
``ValueError`` (:issue:`4303`, :issue:`4305`)

**API Changes**

Expand Down
3 changes: 3 additions & 0 deletions doc/source/v0.12.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ Other Enhancements
- ``read_html`` now raises when no tables are found and BeautifulSoup==4.2.0
is detected (:issue:`4214`)

- ``read_html`` now raises a ``URLError`` instead of catching and raising a
``ValueError`` (:issue:`4303`, :issue:`4305`)

Experimental Features
~~~~~~~~~~~~~~~~~~~~~

Expand Down
7 changes: 2 additions & 5 deletions pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ def _read(io):
raw_text : str
"""
if _is_url(io):
try:
with urlopen(io) as url:
raw_text = url.read()
except urllib2.URLError:
raise ValueError('Invalid URL: "{0}"'.format(io))
with urlopen(io) as url:
raw_text = url.read()
elif hasattr(io, 'read'):
raw_text = io.read()
elif os.path.isfile(io):
Expand Down
13 changes: 10 additions & 3 deletions pandas/io/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import TestCase
import warnings
from distutils.version import LooseVersion
import urllib2

import nose
from nose.tools import assert_raises
Expand All @@ -24,7 +25,7 @@
from pandas.util.testing import (assert_frame_equal, network,
get_data_path)

from pandas.util.testing import makeCustomDataframe as mkdf
from pandas.util.testing import makeCustomDataframe as mkdf, rands


def _have_module(module_name):
Expand Down Expand Up @@ -285,9 +286,15 @@ def test_file_like(self):

assert_framelist_equal(df1, df2)

@network
def test_bad_url_protocol(self):
self.assertRaises(ValueError, self.run_read_html, 'git://github.com',
'.*Water.*')
self.assertRaises(urllib2.URLError, self.run_read_html,
'git://github.com', '.*Water.*')

@network
def test_invalid_url(self):
self.assertRaises(urllib2.URLError, self.run_read_html,
'http://www.a23950sdfa908sd.com')

@slow
def test_file_url(self):
Expand Down