Skip to content

ENH: more distinguish name for widths arugment in read_fwf #34953

Open
@erfannariman

Description

@erfannariman

Is your feature request related to a problem?

We ran into the problem that read_fwf uses widths as an argument to define contigious intervals. But because of **kwargs, it will also accept width and not throw a warning or error. In this case it will produce the wrong output, but without seeing the typo, it;s hard to find out what went wrong.

Describe the solution you'd like

Instead of the argument widths, use a more distinguish / informative name like fixed_widths. Or if changing the name is not preferable, we can throw a warning when a width is used in read_fwf instead of widths

API breaking implications

Not sure

Example with using the correct argument widths

d = StringIO("""
AA1234     aaaa     bbb
BB5678     cccc     ddd
CC9999     eeee     fff
""")

fixed_widths = [2, 4, 9, 8]
df = pd.read_fwf(d, widths=fixed_widths)

  Unnamed: 0  Unnamed: 1 Unnamed: 2 Unnamed: 3
0         AA        1234       aaaa        bbb
1         BB        5678       cccc        ddd
2         CC        9999       eeee        fff

Example using the wrong argument width:

d = StringIO("""
AA1234     aaaa     bbb
BB5678     cccc     ddd
CC9999     eeee     fff
""")

fixed_widths = [2, 4, 9, 8]
df = pd.read_fwf(d, width=fixed_widths)

  Unnamed: 0 Unnamed: 1 Unnamed: 2
0     AA1234       aaaa        bbb
1     BB5678       cccc        ddd
2     CC9999       eeee        fff

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions