Skip to content

Commit fe47bf0

Browse files
committed
CLN: remove try suite in _read
A skip will now occur if a call to urlopen or a read from the resulting object throws a urllib2.URLError exception
1 parent c1e15cc commit fe47bf0

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ pandas 0.12
111111
of the default datetime.min and datetime.max (respectively), thanks @SleepingPills
112112
- ``read_html`` now raises when no tables are found and BeautifulSoup==4.2.0
113113
is detected (:issue:`4214`)
114+
- ``read_html`` now raises a ``URLError`` instead of catching and raising a
115+
``ValueError`` (:issue:`4303`, :issue:`4305`)
114116

115117
**API Changes**
116118

doc/source/v0.12.0.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ Other Enhancements
348348
- ``read_html`` now raises when no tables are found and BeautifulSoup==4.2.0
349349
is detected (:issue:`4214`)
350350

351+
- ``read_html`` now raises a ``URLError`` instead of catching and raising a
352+
``ValueError`` (:issue:`4303`, :issue:`4305`)
353+
351354
Experimental Features
352355
~~~~~~~~~~~~~~~~~~~~~
353356

pandas/io/html.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,8 @@ def _read(io):
113113
raw_text : str
114114
"""
115115
if _is_url(io):
116-
try:
117-
with urlopen(io) as url:
118-
raw_text = url.read()
119-
except urllib2.URLError:
120-
raise ValueError('Invalid URL: "{0}"'.format(io))
116+
with urlopen(io) as url:
117+
raw_text = url.read()
121118
elif hasattr(io, 'read'):
122119
raw_text = io.read()
123120
elif os.path.isfile(io):

pandas/io/tests/test_html.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from unittest import TestCase
55
import warnings
66
from distutils.version import LooseVersion
7+
import urllib2
78

89
import nose
910
from nose.tools import assert_raises
@@ -24,7 +25,7 @@
2425
from pandas.util.testing import (assert_frame_equal, network,
2526
get_data_path)
2627

27-
from pandas.util.testing import makeCustomDataframe as mkdf
28+
from pandas.util.testing import makeCustomDataframe as mkdf, rands
2829

2930

3031
def _have_module(module_name):
@@ -285,9 +286,15 @@ def test_file_like(self):
285286

286287
assert_framelist_equal(df1, df2)
287288

289+
@network
288290
def test_bad_url_protocol(self):
289-
self.assertRaises(ValueError, self.run_read_html, 'git://github.com',
290-
'.*Water.*')
291+
self.assertRaises(urllib2.URLError, self.run_read_html,
292+
'git://github.com', '.*Water.*')
293+
294+
@network
295+
def test_invalid_url(self):
296+
self.assertRaises(urllib2.URLError, self.run_read_html,
297+
'http://www.a23950sdfa908sd.com')
291298

292299
@slow
293300
def test_file_url(self):

0 commit comments

Comments
 (0)