Skip to content

Commit 6dc5937

Browse files
committed
read_fwf with urlopen test GH#26376
Signed-off-by: Liang Yan <ckgppl_yan@sina.cn>
1 parent 5c4cc4a commit 6dc5937

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

pandas/tests/io/parser/test_read_fwf.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929
from pandas.tests.io.test_compression import _compression_to_extension
3030

31+
from pandas.io.common import urlopen
3132
from pandas.io.parsers import (
3233
read_csv,
3334
read_fwf,
@@ -1010,3 +1011,48 @@ def test_invalid_dtype_backend():
10101011
)
10111012
with pytest.raises(ValueError, match=msg):
10121013
read_fwf("test", dtype_backend="numpy")
1014+
1015+
1016+
@pytest.mark.network
1017+
@tm.network(
1018+
url=("ftp://ftp.ncdc.noaa.gov/pub/data/igra/igra2-station-list.txt"),
1019+
)
1020+
def test_url_urlopen():
1021+
url = "ftp://ftp.ncdc.noaa.gov/pub/data/igra/igra2-station-list.txt"
1022+
with urlopen(url) as f:
1023+
expected = pd.Index(
1024+
[
1025+
"CC",
1026+
"Network",
1027+
"Code",
1028+
"StationId",
1029+
"Latitude",
1030+
"Longitude",
1031+
"Elev",
1032+
"dummy",
1033+
"StationName",
1034+
"From",
1035+
"To",
1036+
"Nrec",
1037+
],
1038+
dtype="object",
1039+
)
1040+
result = read_fwf(
1041+
f,
1042+
widths=(2, 1, 3, 5, 9, 10, 7, 4, 30, 5, 5, 7),
1043+
names=(
1044+
"CC",
1045+
"Network",
1046+
"Code",
1047+
"StationId",
1048+
"Latitude",
1049+
"Longitude",
1050+
"Elev",
1051+
"dummy",
1052+
"StationName",
1053+
"From",
1054+
"To",
1055+
"Nrec",
1056+
),
1057+
).columns
1058+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)