|
2 | 2 |
|
3 | 3 | from pandas.compat import u, range, map, openpyxl_compat
|
4 | 4 | from datetime import datetime, date, time
|
| 5 | +import sys |
5 | 6 | import os
|
6 | 7 | from distutils.version import LooseVersion
|
7 | 8 |
|
|
11 | 12 |
|
12 | 13 | from numpy import nan
|
13 | 14 | import numpy as np
|
| 15 | +from numpy.testing.decorators import slow |
14 | 16 |
|
15 | 17 | from pandas import DataFrame, Index, MultiIndex
|
16 | 18 | from pandas.io.parsers import read_csv
|
17 | 19 | from pandas.io.excel import (
|
18 | 20 | ExcelFile, ExcelWriter, read_excel, _XlwtWriter, _OpenpyxlWriter,
|
19 | 21 | register_writer, _XlsxWriter
|
20 | 22 | )
|
| 23 | +from pandas.io.common import URLError |
21 | 24 | from pandas.util.testing import ensure_clean
|
22 | 25 | from pandas.core.config import set_option, get_option
|
23 | 26 | import pandas.util.testing as tm
|
@@ -280,6 +283,39 @@ def test_read_xlrd_Book(self):
|
280 | 283 | result = read_excel(book, sheetname="SheetA", engine="xlrd")
|
281 | 284 | tm.assert_frame_equal(df, result)
|
282 | 285 |
|
| 286 | + @tm.network |
| 287 | + def test_read_from_http_url(self): |
| 288 | + _skip_if_no_xlrd() |
| 289 | + |
| 290 | + url = ('https://raw.github.com/pydata/pandas/master/' |
| 291 | + 'pandas/io/tests/data/test.xlsx') |
| 292 | + url_table = read_excel(url) |
| 293 | + dirpath = tm.get_data_path() |
| 294 | + localtable = os.path.join(dirpath, 'test.xlsx') |
| 295 | + local_table = read_excel(localtable) |
| 296 | + tm.assert_frame_equal(url_table, local_table) |
| 297 | + |
| 298 | + @slow |
| 299 | + def test_read_from_file_url(self): |
| 300 | + _skip_if_no_xlrd() |
| 301 | + |
| 302 | + # FILE |
| 303 | + if sys.version_info[:2] < (2, 6): |
| 304 | + raise nose.SkipTest("file:// not supported with Python < 2.6") |
| 305 | + dirpath = tm.get_data_path() |
| 306 | + localtable = os.path.join(dirpath, 'test.xlsx') |
| 307 | + local_table = read_excel(localtable) |
| 308 | + |
| 309 | + try: |
| 310 | + url_table = read_excel('file://localhost/' + localtable) |
| 311 | + except URLError: |
| 312 | + # fails on some systems |
| 313 | + raise nose.SkipTest("failing on %s" % |
| 314 | + ' '.join(platform.uname()).strip()) |
| 315 | + |
| 316 | + tm.assert_frame_equal(url_table, local_table) |
| 317 | + |
| 318 | + |
283 | 319 | def test_xlsx_table(self):
|
284 | 320 | _skip_if_no_xlrd()
|
285 | 321 | _skip_if_no_openpyxl()
|
|
0 commit comments