test_read_fwf.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests the 'read_fwf' function in parsers.py. This
  4. test suite is independent of the others because the
  5. engine is set to 'python-fwf' internally.
  6. """
  7. from datetime import datetime
  8. import numpy as np
  9. import pytest
  10. import pandas.compat as compat
  11. from pandas.compat import BytesIO, StringIO
  12. import pandas as pd
  13. from pandas import DataFrame, DatetimeIndex
  14. import pandas.util.testing as tm
  15. from pandas.io.parsers import EmptyDataError, read_csv, read_fwf
  16. def test_basic():
  17. data = """\
  18. A B C D
  19. 201158 360.242940 149.910199 11950.7
  20. 201159 444.953632 166.985655 11788.4
  21. 201160 364.136849 183.628767 11806.2
  22. 201161 413.836124 184.375703 11916.8
  23. 201162 502.953953 173.237159 12468.3
  24. """
  25. result = read_fwf(StringIO(data))
  26. expected = DataFrame([[201158, 360.242940, 149.910199, 11950.7],
  27. [201159, 444.953632, 166.985655, 11788.4],
  28. [201160, 364.136849, 183.628767, 11806.2],
  29. [201161, 413.836124, 184.375703, 11916.8],
  30. [201162, 502.953953, 173.237159, 12468.3]],
  31. columns=["A", "B", "C", "D"])
  32. tm.assert_frame_equal(result, expected)
  33. def test_colspecs():
  34. data = """\
  35. A B C D E
  36. 201158 360.242940 149.910199 11950.7
  37. 201159 444.953632 166.985655 11788.4
  38. 201160 364.136849 183.628767 11806.2
  39. 201161 413.836124 184.375703 11916.8
  40. 201162 502.953953 173.237159 12468.3
  41. """
  42. colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)]
  43. result = read_fwf(StringIO(data), colspecs=colspecs)
  44. expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7],
  45. [2011, 59, 444.953632, 166.985655, 11788.4],
  46. [2011, 60, 364.136849, 183.628767, 11806.2],
  47. [2011, 61, 413.836124, 184.375703, 11916.8],
  48. [2011, 62, 502.953953, 173.237159, 12468.3]],
  49. columns=["A", "B", "C", "D", "E"])
  50. tm.assert_frame_equal(result, expected)
  51. def test_widths():
  52. data = """\
  53. A B C D E
  54. 2011 58 360.242940 149.910199 11950.7
  55. 2011 59 444.953632 166.985655 11788.4
  56. 2011 60 364.136849 183.628767 11806.2
  57. 2011 61 413.836124 184.375703 11916.8
  58. 2011 62 502.953953 173.237159 12468.3
  59. """
  60. result = read_fwf(StringIO(data), widths=[5, 5, 13, 13, 7])
  61. expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7],
  62. [2011, 59, 444.953632, 166.985655, 11788.4],
  63. [2011, 60, 364.136849, 183.628767, 11806.2],
  64. [2011, 61, 413.836124, 184.375703, 11916.8],
  65. [2011, 62, 502.953953, 173.237159, 12468.3]],
  66. columns=["A", "B", "C", "D", "E"])
  67. tm.assert_frame_equal(result, expected)
  68. def test_non_space_filler():
  69. # From Thomas Kluyver:
  70. #
  71. # Apparently, some non-space filler characters can be seen, this is
  72. # supported by specifying the 'delimiter' character:
  73. #
  74. # http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r1mx/index.jsp?topic=/com.ibm.wbit.612.help.config.doc/topics/rfixwidth.html
  75. data = """\
  76. A~~~~B~~~~C~~~~~~~~~~~~D~~~~~~~~~~~~E
  77. 201158~~~~360.242940~~~149.910199~~~11950.7
  78. 201159~~~~444.953632~~~166.985655~~~11788.4
  79. 201160~~~~364.136849~~~183.628767~~~11806.2
  80. 201161~~~~413.836124~~~184.375703~~~11916.8
  81. 201162~~~~502.953953~~~173.237159~~~12468.3
  82. """
  83. colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)]
  84. result = read_fwf(StringIO(data), colspecs=colspecs, delimiter="~")
  85. expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7],
  86. [2011, 59, 444.953632, 166.985655, 11788.4],
  87. [2011, 60, 364.136849, 183.628767, 11806.2],
  88. [2011, 61, 413.836124, 184.375703, 11916.8],
  89. [2011, 62, 502.953953, 173.237159, 12468.3]],
  90. columns=["A", "B", "C", "D", "E"])
  91. tm.assert_frame_equal(result, expected)
  92. def test_over_specified():
  93. data = """\
  94. A B C D E
  95. 201158 360.242940 149.910199 11950.7
  96. 201159 444.953632 166.985655 11788.4
  97. 201160 364.136849 183.628767 11806.2
  98. 201161 413.836124 184.375703 11916.8
  99. 201162 502.953953 173.237159 12468.3
  100. """
  101. colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)]
  102. with pytest.raises(ValueError, match="must specify only one of"):
  103. read_fwf(StringIO(data), colspecs=colspecs, widths=[6, 10, 10, 7])
  104. def test_under_specified():
  105. data = """\
  106. A B C D E
  107. 201158 360.242940 149.910199 11950.7
  108. 201159 444.953632 166.985655 11788.4
  109. 201160 364.136849 183.628767 11806.2
  110. 201161 413.836124 184.375703 11916.8
  111. 201162 502.953953 173.237159 12468.3
  112. """
  113. with pytest.raises(ValueError, match="Must specify either"):
  114. read_fwf(StringIO(data), colspecs=None, widths=None)
  115. def test_read_csv_compat():
  116. csv_data = """\
  117. A,B,C,D,E
  118. 2011,58,360.242940,149.910199,11950.7
  119. 2011,59,444.953632,166.985655,11788.4
  120. 2011,60,364.136849,183.628767,11806.2
  121. 2011,61,413.836124,184.375703,11916.8
  122. 2011,62,502.953953,173.237159,12468.3
  123. """
  124. expected = read_csv(StringIO(csv_data), engine="python")
  125. fwf_data = """\
  126. A B C D E
  127. 201158 360.242940 149.910199 11950.7
  128. 201159 444.953632 166.985655 11788.4
  129. 201160 364.136849 183.628767 11806.2
  130. 201161 413.836124 184.375703 11916.8
  131. 201162 502.953953 173.237159 12468.3
  132. """
  133. colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)]
  134. result = read_fwf(StringIO(fwf_data), colspecs=colspecs)
  135. tm.assert_frame_equal(result, expected)
  136. def test_bytes_io_input():
  137. if not compat.PY3:
  138. pytest.skip("Bytes-related test - only needs to work on Python 3")
  139. result = read_fwf(BytesIO("שלום\nשלום".encode('utf8')),
  140. widths=[2, 2], encoding="utf8")
  141. expected = DataFrame([["של", "ום"]], columns=["של", "ום"])
  142. tm.assert_frame_equal(result, expected)
  143. def test_fwf_colspecs_is_list_or_tuple():
  144. data = """index,A,B,C,D
  145. foo,2,3,4,5
  146. bar,7,8,9,10
  147. baz,12,13,14,15
  148. qux,12,13,14,15
  149. foo2,12,13,14,15
  150. bar2,12,13,14,15
  151. """
  152. msg = "column specifications must be a list or tuple.+"
  153. with pytest.raises(TypeError, match=msg):
  154. read_fwf(StringIO(data), colspecs={"a": 1}, delimiter=",")
  155. def test_fwf_colspecs_is_list_or_tuple_of_two_element_tuples():
  156. data = """index,A,B,C,D
  157. foo,2,3,4,5
  158. bar,7,8,9,10
  159. baz,12,13,14,15
  160. qux,12,13,14,15
  161. foo2,12,13,14,15
  162. bar2,12,13,14,15
  163. """
  164. msg = "Each column specification must be.+"
  165. with pytest.raises(TypeError, match=msg):
  166. read_fwf(StringIO(data), [("a", 1)])
  167. @pytest.mark.parametrize("colspecs,exp_data", [
  168. ([(0, 3), (3, None)], [[123, 456], [456, 789]]),
  169. ([(None, 3), (3, 6)], [[123, 456], [456, 789]]),
  170. ([(0, None), (3, None)], [[123456, 456], [456789, 789]]),
  171. ([(None, None), (3, 6)], [[123456, 456], [456789, 789]]),
  172. ])
  173. def test_fwf_colspecs_none(colspecs, exp_data):
  174. # see gh-7079
  175. data = """\
  176. 123456
  177. 456789
  178. """
  179. expected = DataFrame(exp_data)
  180. result = read_fwf(StringIO(data), colspecs=colspecs, header=None)
  181. tm.assert_frame_equal(result, expected)
  182. @pytest.mark.parametrize("infer_nrows,exp_data", [
  183. # infer_nrows --> colspec == [(2, 3), (5, 6)]
  184. (1, [[1, 2], [3, 8]]),
  185. # infer_nrows > number of rows
  186. (10, [[1, 2], [123, 98]]),
  187. ])
  188. def test_fwf_colspecs_infer_nrows(infer_nrows, exp_data):
  189. # see gh-15138
  190. data = """\
  191. 1 2
  192. 123 98
  193. """
  194. expected = DataFrame(exp_data)
  195. result = read_fwf(StringIO(data), infer_nrows=infer_nrows, header=None)
  196. tm.assert_frame_equal(result, expected)
  197. def test_fwf_regression():
  198. # see gh-3594
  199. #
  200. # Turns out "T060" is parsable as a datetime slice!
  201. tz_list = [1, 10, 20, 30, 60, 80, 100]
  202. widths = [16] + [8] * len(tz_list)
  203. names = ["SST"] + ["T%03d" % z for z in tz_list[1:]]
  204. data = """ 2009164202000 9.5403 9.4105 8.6571 7.8372 6.0612 5.8843 5.5192
  205. 2009164203000 9.5435 9.2010 8.6167 7.8176 6.0804 5.8728 5.4869
  206. 2009164204000 9.5873 9.1326 8.4694 7.5889 6.0422 5.8526 5.4657
  207. 2009164205000 9.5810 9.0896 8.4009 7.4652 6.0322 5.8189 5.4379
  208. 2009164210000 9.6034 9.0897 8.3822 7.4905 6.0908 5.7904 5.4039
  209. """
  210. result = read_fwf(StringIO(data), index_col=0, header=None, names=names,
  211. widths=widths, parse_dates=True,
  212. date_parser=lambda s: datetime.strptime(s, "%Y%j%H%M%S"))
  213. expected = DataFrame([
  214. [9.5403, 9.4105, 8.6571, 7.8372, 6.0612, 5.8843, 5.5192],
  215. [9.5435, 9.2010, 8.6167, 7.8176, 6.0804, 5.8728, 5.4869],
  216. [9.5873, 9.1326, 8.4694, 7.5889, 6.0422, 5.8526, 5.4657],
  217. [9.5810, 9.0896, 8.4009, 7.4652, 6.0322, 5.8189, 5.4379],
  218. [9.6034, 9.0897, 8.3822, 7.4905, 6.0908, 5.7904, 5.4039],
  219. ], index=DatetimeIndex(["2009-06-13 20:20:00", "2009-06-13 20:30:00",
  220. "2009-06-13 20:40:00", "2009-06-13 20:50:00",
  221. "2009-06-13 21:00:00"]),
  222. columns=["SST", "T010", "T020", "T030", "T060", "T080", "T100"])
  223. tm.assert_frame_equal(result, expected)
  224. def test_fwf_for_uint8():
  225. data = """1421302965.213420 PRI=3 PGN=0xef00 DST=0x17 SRC=0x28 04 154 00 00 00 00 00 127
  226. 1421302964.226776 PRI=6 PGN=0xf002 SRC=0x47 243 00 00 255 247 00 00 71""" # noqa
  227. df = read_fwf(StringIO(data),
  228. colspecs=[(0, 17), (25, 26), (33, 37),
  229. (49, 51), (58, 62), (63, 1000)],
  230. names=["time", "pri", "pgn", "dst", "src", "data"],
  231. converters={
  232. "pgn": lambda x: int(x, 16),
  233. "src": lambda x: int(x, 16),
  234. "dst": lambda x: int(x, 16),
  235. "data": lambda x: len(x.split(" "))})
  236. expected = DataFrame([[1421302965.213420, 3, 61184, 23, 40, 8],
  237. [1421302964.226776, 6, 61442, None, 71, 8]],
  238. columns=["time", "pri", "pgn",
  239. "dst", "src", "data"])
  240. expected["dst"] = expected["dst"].astype(object)
  241. tm.assert_frame_equal(df, expected)
  242. @pytest.mark.parametrize("comment", ["#", "~", "!"])
  243. def test_fwf_comment(comment):
  244. data = """\
  245. 1 2. 4 #hello world
  246. 5 NaN 10.0
  247. """
  248. data = data.replace("#", comment)
  249. colspecs = [(0, 3), (4, 9), (9, 25)]
  250. expected = DataFrame([[1, 2., 4], [5, np.nan, 10.]])
  251. result = read_fwf(StringIO(data), colspecs=colspecs,
  252. header=None, comment=comment)
  253. tm.assert_almost_equal(result, expected)
  254. @pytest.mark.parametrize("thousands", [",", "#", "~"])
  255. def test_fwf_thousands(thousands):
  256. data = """\
  257. 1 2,334.0 5
  258. 10 13 10.
  259. """
  260. data = data.replace(",", thousands)
  261. colspecs = [(0, 3), (3, 11), (12, 16)]
  262. expected = DataFrame([[1, 2334., 5], [10, 13, 10.]])
  263. result = read_fwf(StringIO(data), header=None,
  264. colspecs=colspecs, thousands=thousands)
  265. tm.assert_almost_equal(result, expected)
  266. @pytest.mark.parametrize("header", [True, False])
  267. def test_bool_header_arg(header):
  268. # see gh-6114
  269. data = """\
  270. MyColumn
  271. a
  272. b
  273. a
  274. b"""
  275. msg = "Passing a bool to header is invalid"
  276. with pytest.raises(TypeError, match=msg):
  277. read_fwf(StringIO(data), header=header)
  278. def test_full_file():
  279. # File with all values.
  280. test = """index A B C
  281. 2000-01-03T00:00:00 0.980268513777 3 foo
  282. 2000-01-04T00:00:00 1.04791624281 -4 bar
  283. 2000-01-05T00:00:00 0.498580885705 73 baz
  284. 2000-01-06T00:00:00 1.12020151869 1 foo
  285. 2000-01-07T00:00:00 0.487094399463 0 bar
  286. 2000-01-10T00:00:00 0.836648671666 2 baz
  287. 2000-01-11T00:00:00 0.157160753327 34 foo"""
  288. colspecs = ((0, 19), (21, 35), (38, 40), (42, 45))
  289. expected = read_fwf(StringIO(test), colspecs=colspecs)
  290. result = read_fwf(StringIO(test))
  291. tm.assert_frame_equal(result, expected)
  292. def test_full_file_with_missing():
  293. # File with missing values.
  294. test = """index A B C
  295. 2000-01-03T00:00:00 0.980268513777 3 foo
  296. 2000-01-04T00:00:00 1.04791624281 -4 bar
  297. 0.498580885705 73 baz
  298. 2000-01-06T00:00:00 1.12020151869 1 foo
  299. 2000-01-07T00:00:00 0 bar
  300. 2000-01-10T00:00:00 0.836648671666 2 baz
  301. 34"""
  302. colspecs = ((0, 19), (21, 35), (38, 40), (42, 45))
  303. expected = read_fwf(StringIO(test), colspecs=colspecs)
  304. result = read_fwf(StringIO(test))
  305. tm.assert_frame_equal(result, expected)
  306. def test_full_file_with_spaces():
  307. # File with spaces in columns.
  308. test = """
  309. Account Name Balance CreditLimit AccountCreated
  310. 101 Keanu Reeves 9315.45 10000.00 1/17/1998
  311. 312 Gerard Butler 90.00 1000.00 8/6/2003
  312. 868 Jennifer Love Hewitt 0 17000.00 5/25/1985
  313. 761 Jada Pinkett-Smith 49654.87 100000.00 12/5/2006
  314. 317 Bill Murray 789.65 5000.00 2/5/2007
  315. """.strip("\r\n")
  316. colspecs = ((0, 7), (8, 28), (30, 38), (42, 53), (56, 70))
  317. expected = read_fwf(StringIO(test), colspecs=colspecs)
  318. result = read_fwf(StringIO(test))
  319. tm.assert_frame_equal(result, expected)
  320. def test_full_file_with_spaces_and_missing():
  321. # File with spaces and missing values in columns.
  322. test = """
  323. Account Name Balance CreditLimit AccountCreated
  324. 101 10000.00 1/17/1998
  325. 312 Gerard Butler 90.00 1000.00 8/6/2003
  326. 868 5/25/1985
  327. 761 Jada Pinkett-Smith 49654.87 100000.00 12/5/2006
  328. 317 Bill Murray 789.65
  329. """.strip("\r\n")
  330. colspecs = ((0, 7), (8, 28), (30, 38), (42, 53), (56, 70))
  331. expected = read_fwf(StringIO(test), colspecs=colspecs)
  332. result = read_fwf(StringIO(test))
  333. tm.assert_frame_equal(result, expected)
  334. def test_messed_up_data():
  335. # Completely messed up file.
  336. test = """
  337. Account Name Balance Credit Limit Account Created
  338. 101 10000.00 1/17/1998
  339. 312 Gerard Butler 90.00 1000.00
  340. 761 Jada Pinkett-Smith 49654.87 100000.00 12/5/2006
  341. 317 Bill Murray 789.65
  342. """.strip("\r\n")
  343. colspecs = ((2, 10), (15, 33), (37, 45), (49, 61), (64, 79))
  344. expected = read_fwf(StringIO(test), colspecs=colspecs)
  345. result = read_fwf(StringIO(test))
  346. tm.assert_frame_equal(result, expected)
  347. def test_multiple_delimiters():
  348. test = r"""
  349. col1~~~~~col2 col3++++++++++++++++++col4
  350. ~~22.....11.0+++foo~~~~~~~~~~Keanu Reeves
  351. 33+++122.33\\\bar.........Gerard Butler
  352. ++44~~~~12.01 baz~~Jennifer Love Hewitt
  353. ~~55 11+++foo++++Jada Pinkett-Smith
  354. ..66++++++.03~~~bar Bill Murray
  355. """.strip("\r\n")
  356. delimiter = " +~.\\"
  357. colspecs = ((0, 4), (7, 13), (15, 19), (21, 41))
  358. expected = read_fwf(StringIO(test), colspecs=colspecs, delimiter=delimiter)
  359. result = read_fwf(StringIO(test), delimiter=delimiter)
  360. tm.assert_frame_equal(result, expected)
  361. def test_variable_width_unicode():
  362. if not compat.PY3:
  363. pytest.skip("Bytes-related test - only needs to work on Python 3")
  364. data = """
  365. שלום שלום
  366. ום שלל
  367. של ום
  368. """.strip("\r\n")
  369. encoding = "utf8"
  370. kwargs = dict(header=None, encoding=encoding)
  371. expected = read_fwf(BytesIO(data.encode(encoding)),
  372. colspecs=[(0, 4), (5, 9)], **kwargs)
  373. result = read_fwf(BytesIO(data.encode(encoding)), **kwargs)
  374. tm.assert_frame_equal(result, expected)
  375. @pytest.mark.parametrize("dtype", [
  376. dict(), {"a": "float64", "b": str, "c": "int32"}
  377. ])
  378. def test_dtype(dtype):
  379. data = """ a b c
  380. 1 2 3.2
  381. 3 4 5.2
  382. """
  383. colspecs = [(0, 5), (5, 10), (10, None)]
  384. result = read_fwf(StringIO(data), colspecs=colspecs, dtype=dtype)
  385. expected = pd.DataFrame({
  386. "a": [1, 3], "b": [2, 4],
  387. "c": [3.2, 5.2]}, columns=["a", "b", "c"])
  388. for col, dt in dtype.items():
  389. expected[col] = expected[col].astype(dt)
  390. tm.assert_frame_equal(result, expected)
  391. def test_skiprows_inference():
  392. # see gh-11256
  393. data = """
  394. Text contained in the file header
  395. DataCol1 DataCol2
  396. 0.0 1.0
  397. 101.6 956.1
  398. """.strip()
  399. skiprows = 2
  400. expected = read_csv(StringIO(data), skiprows=skiprows,
  401. delim_whitespace=True)
  402. result = read_fwf(StringIO(data), skiprows=skiprows)
  403. tm.assert_frame_equal(result, expected)
  404. def test_skiprows_by_index_inference():
  405. data = """
  406. To be skipped
  407. Not To Be Skipped
  408. Once more to be skipped
  409. 123 34 8 123
  410. 456 78 9 456
  411. """.strip()
  412. skiprows = [0, 2]
  413. expected = read_csv(StringIO(data), skiprows=skiprows,
  414. delim_whitespace=True)
  415. result = read_fwf(StringIO(data), skiprows=skiprows)
  416. tm.assert_frame_equal(result, expected)
  417. def test_skiprows_inference_empty():
  418. data = """
  419. AA BBB C
  420. 12 345 6
  421. 78 901 2
  422. """.strip()
  423. msg = "No rows from which to infer column width"
  424. with pytest.raises(EmptyDataError, match=msg):
  425. read_fwf(StringIO(data), skiprows=3)
  426. def test_whitespace_preservation():
  427. # see gh-16772
  428. header = None
  429. csv_data = """
  430. a ,bbb
  431. cc,dd """
  432. fwf_data = """
  433. a bbb
  434. ccdd """
  435. result = read_fwf(StringIO(fwf_data), widths=[3, 3],
  436. header=header, skiprows=[0], delimiter="\n\t")
  437. expected = read_csv(StringIO(csv_data), header=header)
  438. tm.assert_frame_equal(result, expected)
  439. def test_default_delimiter():
  440. header = None
  441. csv_data = """
  442. a,bbb
  443. cc,dd"""
  444. fwf_data = """
  445. a \tbbb
  446. cc\tdd """
  447. result = read_fwf(StringIO(fwf_data), widths=[3, 3],
  448. header=header, skiprows=[0])
  449. expected = read_csv(StringIO(csv_data), header=header)
  450. tm.assert_frame_equal(result, expected)
  451. @pytest.mark.parametrize("infer", [True, False, None])
  452. def test_fwf_compression(compression_only, infer):
  453. data = """1111111111
  454. 2222222222
  455. 3333333333""".strip()
  456. compression = compression_only
  457. extension = "gz" if compression == "gzip" else compression
  458. kwargs = dict(widths=[5, 5], names=["one", "two"])
  459. expected = read_fwf(StringIO(data), **kwargs)
  460. if compat.PY3:
  461. data = bytes(data, encoding="utf-8")
  462. with tm.ensure_clean(filename="tmp." + extension) as path:
  463. tm.write_to_compressed(compression, path, data)
  464. if infer is not None:
  465. kwargs["compression"] = "infer" if infer else compression
  466. result = read_fwf(path, **kwargs)
  467. tm.assert_frame_equal(result, expected)