Python pandas.io.parsers.read_fwf() Examples
The following are 30
code examples of pandas.io.parsers.read_fwf().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.io.parsers
, or try the search function
.
Example #1
Source File: test_read_fwf.py From vnpy_crypto with MIT License | 9 votes |
def test_fwf_colspecs_None(self): # GH 7079 data = """\ 123456 456789 """ colspecs = [(0, 3), (3, None)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123, 456], [456, 789]]) tm.assert_frame_equal(result, expected) colspecs = [(None, 3), (3, 6)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123, 456], [456, 789]]) tm.assert_frame_equal(result, expected) colspecs = [(0, None), (3, None)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123456, 456], [456789, 789]]) tm.assert_frame_equal(result, expected) colspecs = [(None, None), (3, 6)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123456, 456], [456789, 789]]) tm.assert_frame_equal(result, expected)
Example #2
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_fwf_for_uint8(): data = """1421302965.213420 PRI=3 PGN=0xef00 DST=0x17 SRC=0x28 04 154 00 00 00 00 00 127 1421302964.226776 PRI=6 PGN=0xf002 SRC=0x47 243 00 00 255 247 00 00 71""" # noqa df = read_fwf(StringIO(data), colspecs=[(0, 17), (25, 26), (33, 37), (49, 51), (58, 62), (63, 1000)], names=["time", "pri", "pgn", "dst", "src", "data"], converters={ "pgn": lambda x: int(x, 16), "src": lambda x: int(x, 16), "dst": lambda x: int(x, 16), "data": lambda x: len(x.split(" "))}) expected = DataFrame([[1421302965.213420, 3, 61184, 23, 40, 8], [1421302964.226776, 6, 61442, None, 71, 8]], columns=["time", "pri", "pgn", "dst", "src", "data"]) expected["dst"] = expected["dst"].astype(object) tm.assert_frame_equal(df, expected)
Example #3
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_fwf_for_uint8(): data = """1421302965.213420 PRI=3 PGN=0xef00 DST=0x17 SRC=0x28 04 154 00 00 00 00 00 127 1421302964.226776 PRI=6 PGN=0xf002 SRC=0x47 243 00 00 255 247 00 00 71""" # noqa df = read_fwf(StringIO(data), colspecs=[(0, 17), (25, 26), (33, 37), (49, 51), (58, 62), (63, 1000)], names=["time", "pri", "pgn", "dst", "src", "data"], converters={ "pgn": lambda x: int(x, 16), "src": lambda x: int(x, 16), "dst": lambda x: int(x, 16), "data": lambda x: len(x.split(" "))}) expected = DataFrame([[1421302965.213420, 3, 61184, 23, 40, 8], [1421302964.226776, 6, 61442, None, 71, 8]], columns=["time", "pri", "pgn", "dst", "src", "data"]) expected["dst"] = expected["dst"].astype(object) tm.assert_frame_equal(df, expected)
Example #4
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_fwf_compression(compression_only, infer): data = """1111111111 2222222222 3333333333""".strip() compression = compression_only extension = "gz" if compression == "gzip" else compression kwargs = dict(widths=[5, 5], names=["one", "two"]) expected = read_fwf(StringIO(data), **kwargs) if compat.PY3: data = bytes(data, encoding="utf-8") with tm.ensure_clean(filename="tmp." + extension) as path: tm.write_to_compressed(compression, path, data) if infer is not None: kwargs["compression"] = "infer" if infer else compression result = read_fwf(path, **kwargs) tm.assert_frame_equal(result, expected)
Example #5
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_dtype(dtype): data = """ a b c 1 2 3.2 3 4 5.2 """ colspecs = [(0, 5), (5, 10), (10, None)] result = read_fwf(StringIO(data), colspecs=colspecs, dtype=dtype) expected = pd.DataFrame({ "a": [1, 3], "b": [2, 4], "c": [3.2, 5.2]}, columns=["a", "b", "c"]) for col, dt in dtype.items(): expected[col] = expected[col].astype(dt) tm.assert_frame_equal(result, expected)
Example #6
Source File: test_read_fwf.py From vnpy_crypto with MIT License | 6 votes |
def test_fwf_compression(self): try: import gzip import bz2 except ImportError: pytest.skip("Need gzip and bz2 to run this test") data = """1111111111 2222222222 3333333333""".strip() widths = [5, 5] names = ['one', 'two'] expected = read_fwf(StringIO(data), widths=widths, names=names) if compat.PY3: data = bytes(data, encoding='utf-8') comps = [('gzip', gzip.GzipFile), ('bz2', bz2.BZ2File)] for comp_name, compresser in comps: with tm.ensure_clean() as path: tmp = compresser(path, mode='wb') tmp.write(data) tmp.close() result = read_fwf(path, widths=widths, names=names, compression=comp_name) tm.assert_frame_equal(result, expected)
Example #7
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_dtype(dtype): data = """ a b c 1 2 3.2 3 4 5.2 """ colspecs = [(0, 5), (5, 10), (10, None)] result = read_fwf(StringIO(data), colspecs=colspecs, dtype=dtype) expected = pd.DataFrame({ "a": [1, 3], "b": [2, 4], "c": [3.2, 5.2]}, columns=["a", "b", "c"]) for col, dt in dtype.items(): expected[col] = expected[col].astype(dt) tm.assert_frame_equal(result, expected)
Example #8
Source File: test_read_fwf.py From vnpy_crypto with MIT License | 6 votes |
def test_fwf_regression(self): # GH 3594 # turns out 'T060' is parsable as a datetime slice! tzlist = [1, 10, 20, 30, 60, 80, 100] ntz = len(tzlist) tcolspecs = [16] + [8] * ntz tcolnames = ['SST'] + ["T%03d" % z for z in tzlist[1:]] data = """ 2009164202000 9.5403 9.4105 8.6571 7.8372 6.0612 5.8843 5.5192 2009164203000 9.5435 9.2010 8.6167 7.8176 6.0804 5.8728 5.4869 2009164204000 9.5873 9.1326 8.4694 7.5889 6.0422 5.8526 5.4657 2009164205000 9.5810 9.0896 8.4009 7.4652 6.0322 5.8189 5.4379 2009164210000 9.6034 9.0897 8.3822 7.4905 6.0908 5.7904 5.4039 """ df = read_fwf(StringIO(data), index_col=0, header=None, names=tcolnames, widths=tcolspecs, parse_dates=True, date_parser=lambda s: datetime.strptime(s, '%Y%j%H%M%S')) for c in df.columns: res = df.loc[:, c] assert len(res)
Example #9
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_read_csv_compat(): csv_data = """\ A,B,C,D,E 2011,58,360.242940,149.910199,11950.7 2011,59,444.953632,166.985655,11788.4 2011,60,364.136849,183.628767,11806.2 2011,61,413.836124,184.375703,11916.8 2011,62,502.953953,173.237159,12468.3 """ expected = read_csv(StringIO(csv_data), engine="python") fwf_data = """\ A B C D E 201158 360.242940 149.910199 11950.7 201159 444.953632 166.985655 11788.4 201160 364.136849 183.628767 11806.2 201161 413.836124 184.375703 11916.8 201162 502.953953 173.237159 12468.3 """ colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)] result = read_fwf(StringIO(fwf_data), colspecs=colspecs) tm.assert_frame_equal(result, expected)
Example #10
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_non_space_filler(): # From Thomas Kluyver: # # Apparently, some non-space filler characters can be seen, this is # supported by specifying the 'delimiter' character: # # http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r1mx/index.jsp?topic=/com.ibm.wbit.612.help.config.doc/topics/rfixwidth.html data = """\ A~~~~B~~~~C~~~~~~~~~~~~D~~~~~~~~~~~~E 201158~~~~360.242940~~~149.910199~~~11950.7 201159~~~~444.953632~~~166.985655~~~11788.4 201160~~~~364.136849~~~183.628767~~~11806.2 201161~~~~413.836124~~~184.375703~~~11916.8 201162~~~~502.953953~~~173.237159~~~12468.3 """ colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)] result = read_fwf(StringIO(data), colspecs=colspecs, delimiter="~") expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7], [2011, 59, 444.953632, 166.985655, 11788.4], [2011, 60, 364.136849, 183.628767, 11806.2], [2011, 61, 413.836124, 184.375703, 11916.8], [2011, 62, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D", "E"]) tm.assert_frame_equal(result, expected)
Example #11
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_fwf_compression(compression_only, infer): data = """1111111111 2222222222 3333333333""".strip() compression = compression_only extension = "gz" if compression == "gzip" else compression kwargs = dict(widths=[5, 5], names=["one", "two"]) expected = read_fwf(StringIO(data), **kwargs) if compat.PY3: data = bytes(data, encoding="utf-8") with tm.ensure_clean(filename="tmp." + extension) as path: tm.write_to_compressed(compression, path, data) if infer is not None: kwargs["compression"] = "infer" if infer else compression result = read_fwf(path, **kwargs) tm.assert_frame_equal(result, expected)
Example #12
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_widths(): data = """\ A B C D E 2011 58 360.242940 149.910199 11950.7 2011 59 444.953632 166.985655 11788.4 2011 60 364.136849 183.628767 11806.2 2011 61 413.836124 184.375703 11916.8 2011 62 502.953953 173.237159 12468.3 """ result = read_fwf(StringIO(data), widths=[5, 5, 13, 13, 7]) expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7], [2011, 59, 444.953632, 166.985655, 11788.4], [2011, 60, 364.136849, 183.628767, 11806.2], [2011, 61, 413.836124, 184.375703, 11916.8], [2011, 62, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D", "E"]) tm.assert_frame_equal(result, expected)
Example #13
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_colspecs(): data = """\ A B C D E 201158 360.242940 149.910199 11950.7 201159 444.953632 166.985655 11788.4 201160 364.136849 183.628767 11806.2 201161 413.836124 184.375703 11916.8 201162 502.953953 173.237159 12468.3 """ colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)] result = read_fwf(StringIO(data), colspecs=colspecs) expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7], [2011, 59, 444.953632, 166.985655, 11788.4], [2011, 60, 364.136849, 183.628767, 11806.2], [2011, 61, 413.836124, 184.375703, 11916.8], [2011, 62, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D", "E"]) tm.assert_frame_equal(result, expected)
Example #14
Source File: test_read_fwf.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_fwf_colspecs_None(self): # GH 7079 data = """\ 123456 456789 """ colspecs = [(0, 3), (3, None)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123, 456], [456, 789]]) tm.assert_frame_equal(result, expected) colspecs = [(None, 3), (3, 6)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123, 456], [456, 789]]) tm.assert_frame_equal(result, expected) colspecs = [(0, None), (3, None)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123456, 456], [456789, 789]]) tm.assert_frame_equal(result, expected) colspecs = [(None, None), (3, 6)] result = read_fwf(StringIO(data), colspecs=colspecs, header=None) expected = DataFrame([[123456, 456], [456789, 789]]) tm.assert_frame_equal(result, expected)
Example #15
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_basic(): data = """\ A B C D 201158 360.242940 149.910199 11950.7 201159 444.953632 166.985655 11788.4 201160 364.136849 183.628767 11806.2 201161 413.836124 184.375703 11916.8 201162 502.953953 173.237159 12468.3 """ result = read_fwf(StringIO(data)) expected = DataFrame([[201158, 360.242940, 149.910199, 11950.7], [201159, 444.953632, 166.985655, 11788.4], [201160, 364.136849, 183.628767, 11806.2], [201161, 413.836124, 184.375703, 11916.8], [201162, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D"]) tm.assert_frame_equal(result, expected)
Example #16
Source File: test_read_fwf.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_fwf_compression(self): try: import gzip import bz2 except ImportError: pytest.skip("Need gzip and bz2 to run this test") data = """1111111111 2222222222 3333333333""".strip() widths = [5, 5] names = ['one', 'two'] expected = read_fwf(StringIO(data), widths=widths, names=names) if compat.PY3: data = bytes(data, encoding='utf-8') comps = [('gzip', gzip.GzipFile), ('bz2', bz2.BZ2File)] for comp_name, compresser in comps: with tm.ensure_clean() as path: tmp = compresser(path, mode='wb') tmp.write(data) tmp.close() result = read_fwf(path, widths=widths, names=names, compression=comp_name) tm.assert_frame_equal(result, expected)
Example #17
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_read_csv_compat(): csv_data = """\ A,B,C,D,E 2011,58,360.242940,149.910199,11950.7 2011,59,444.953632,166.985655,11788.4 2011,60,364.136849,183.628767,11806.2 2011,61,413.836124,184.375703,11916.8 2011,62,502.953953,173.237159,12468.3 """ expected = read_csv(StringIO(csv_data), engine="python") fwf_data = """\ A B C D E 201158 360.242940 149.910199 11950.7 201159 444.953632 166.985655 11788.4 201160 364.136849 183.628767 11806.2 201161 413.836124 184.375703 11916.8 201162 502.953953 173.237159 12468.3 """ colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)] result = read_fwf(StringIO(fwf_data), colspecs=colspecs) tm.assert_frame_equal(result, expected)
Example #18
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_basic(): data = """\ A B C D 201158 360.242940 149.910199 11950.7 201159 444.953632 166.985655 11788.4 201160 364.136849 183.628767 11806.2 201161 413.836124 184.375703 11916.8 201162 502.953953 173.237159 12468.3 """ result = read_fwf(StringIO(data)) expected = DataFrame([[201158, 360.242940, 149.910199, 11950.7], [201159, 444.953632, 166.985655, 11788.4], [201160, 364.136849, 183.628767, 11806.2], [201161, 413.836124, 184.375703, 11916.8], [201162, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D"]) tm.assert_frame_equal(result, expected)
Example #19
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_non_space_filler(): # From Thomas Kluyver: # # Apparently, some non-space filler characters can be seen, this is # supported by specifying the 'delimiter' character: # # http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r1mx/index.jsp?topic=/com.ibm.wbit.612.help.config.doc/topics/rfixwidth.html data = """\ A~~~~B~~~~C~~~~~~~~~~~~D~~~~~~~~~~~~E 201158~~~~360.242940~~~149.910199~~~11950.7 201159~~~~444.953632~~~166.985655~~~11788.4 201160~~~~364.136849~~~183.628767~~~11806.2 201161~~~~413.836124~~~184.375703~~~11916.8 201162~~~~502.953953~~~173.237159~~~12468.3 """ colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)] result = read_fwf(StringIO(data), colspecs=colspecs, delimiter="~") expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7], [2011, 59, 444.953632, 166.985655, 11788.4], [2011, 60, 364.136849, 183.628767, 11806.2], [2011, 61, 413.836124, 184.375703, 11916.8], [2011, 62, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D", "E"]) tm.assert_frame_equal(result, expected)
Example #20
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_widths(): data = """\ A B C D E 2011 58 360.242940 149.910199 11950.7 2011 59 444.953632 166.985655 11788.4 2011 60 364.136849 183.628767 11806.2 2011 61 413.836124 184.375703 11916.8 2011 62 502.953953 173.237159 12468.3 """ result = read_fwf(StringIO(data), widths=[5, 5, 13, 13, 7]) expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7], [2011, 59, 444.953632, 166.985655, 11788.4], [2011, 60, 364.136849, 183.628767, 11806.2], [2011, 61, 413.836124, 184.375703, 11916.8], [2011, 62, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D", "E"]) tm.assert_frame_equal(result, expected)
Example #21
Source File: test_read_fwf.py From recruit with Apache License 2.0 | 6 votes |
def test_colspecs(): data = """\ A B C D E 201158 360.242940 149.910199 11950.7 201159 444.953632 166.985655 11788.4 201160 364.136849 183.628767 11806.2 201161 413.836124 184.375703 11916.8 201162 502.953953 173.237159 12468.3 """ colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)] result = read_fwf(StringIO(data), colspecs=colspecs) expected = DataFrame([[2011, 58, 360.242940, 149.910199, 11950.7], [2011, 59, 444.953632, 166.985655, 11788.4], [2011, 60, 364.136849, 183.628767, 11806.2], [2011, 61, 413.836124, 184.375703, 11916.8], [2011, 62, 502.953953, 173.237159, 12468.3]], columns=["A", "B", "C", "D", "E"]) tm.assert_frame_equal(result, expected)
Example #22
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_skiprows_inference_empty(): data = """ AA BBB C 12 345 6 78 901 2 """.strip() msg = "No rows from which to infer column width" with pytest.raises(EmptyDataError, match=msg): read_fwf(StringIO(data), skiprows=3)
Example #23
Source File: test_read_fwf.py From vnpy_crypto with MIT License | 5 votes |
def test_default_delimiter(self): data_expected = """ a,bbb cc,dd""" expected = read_csv(StringIO(data_expected), header=None) test_data = """ a \tbbb cc\tdd """ result = read_fwf(StringIO(test_data), widths=[3, 3], header=None, skiprows=[0]) tm.assert_frame_equal(result, expected)
Example #24
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_fwf_regression(): # see gh-3594 # # Turns out "T060" is parsable as a datetime slice! tz_list = [1, 10, 20, 30, 60, 80, 100] widths = [16] + [8] * len(tz_list) names = ["SST"] + ["T%03d" % z for z in tz_list[1:]] data = """ 2009164202000 9.5403 9.4105 8.6571 7.8372 6.0612 5.8843 5.5192 2009164203000 9.5435 9.2010 8.6167 7.8176 6.0804 5.8728 5.4869 2009164204000 9.5873 9.1326 8.4694 7.5889 6.0422 5.8526 5.4657 2009164205000 9.5810 9.0896 8.4009 7.4652 6.0322 5.8189 5.4379 2009164210000 9.6034 9.0897 8.3822 7.4905 6.0908 5.7904 5.4039 """ result = read_fwf(StringIO(data), index_col=0, header=None, names=names, widths=widths, parse_dates=True, date_parser=lambda s: datetime.strptime(s, "%Y%j%H%M%S")) expected = DataFrame([ [9.5403, 9.4105, 8.6571, 7.8372, 6.0612, 5.8843, 5.5192], [9.5435, 9.2010, 8.6167, 7.8176, 6.0804, 5.8728, 5.4869], [9.5873, 9.1326, 8.4694, 7.5889, 6.0422, 5.8526, 5.4657], [9.5810, 9.0896, 8.4009, 7.4652, 6.0322, 5.8189, 5.4379], [9.6034, 9.0897, 8.3822, 7.4905, 6.0908, 5.7904, 5.4039], ], index=DatetimeIndex(["2009-06-13 20:20:00", "2009-06-13 20:30:00", "2009-06-13 20:40:00", "2009-06-13 20:50:00", "2009-06-13 21:00:00"]), columns=["SST", "T010", "T020", "T030", "T060", "T080", "T100"]) tm.assert_frame_equal(result, expected)
Example #25
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_fwf_colspecs_none(colspecs, exp_data): # see gh-7079 data = """\ 123456 456789 """ expected = DataFrame(exp_data) result = read_fwf(StringIO(data), colspecs=colspecs, header=None) tm.assert_frame_equal(result, expected)
Example #26
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_fwf_colspecs_is_list_or_tuple_of_two_element_tuples(): data = """index,A,B,C,D foo,2,3,4,5 bar,7,8,9,10 baz,12,13,14,15 qux,12,13,14,15 foo2,12,13,14,15 bar2,12,13,14,15 """ msg = "Each column specification must be.+" with pytest.raises(TypeError, match=msg): read_fwf(StringIO(data), [("a", 1)])
Example #27
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_fwf_colspecs_is_list_or_tuple(): data = """index,A,B,C,D foo,2,3,4,5 bar,7,8,9,10 baz,12,13,14,15 qux,12,13,14,15 foo2,12,13,14,15 bar2,12,13,14,15 """ msg = "column specifications must be a list or tuple.+" with pytest.raises(TypeError, match=msg): read_fwf(StringIO(data), colspecs={"a": 1}, delimiter=",")
Example #28
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_bytes_io_input(): if not compat.PY3: pytest.skip("Bytes-related test - only needs to work on Python 3") result = read_fwf(BytesIO("שלום\nשלום".encode('utf8')), widths=[2, 2], encoding="utf8") expected = DataFrame([["של", "ום"]], columns=["של", "ום"]) tm.assert_frame_equal(result, expected)
Example #29
Source File: test_read_fwf.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_over_specified(): data = """\ A B C D E 201158 360.242940 149.910199 11950.7 201159 444.953632 166.985655 11788.4 201160 364.136849 183.628767 11806.2 201161 413.836124 184.375703 11916.8 201162 502.953953 173.237159 12468.3 """ colspecs = [(0, 4), (4, 8), (8, 20), (21, 33), (34, 43)] with pytest.raises(ValueError, match="must specify only one of"): read_fwf(StringIO(data), colspecs=colspecs, widths=[6, 10, 10, 7])
Example #30
Source File: test_read_fwf.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_1000_fwf(self): data = """ 1 2,334.0 5 10 13 10. """ expected = np.array([[1, 2334., 5], [10, 13, 10]]) df = read_fwf(StringIO(data), colspecs=[(0, 3), (3, 11), (12, 16)], thousands=',') tm.assert_almost_equal(df.values, expected)