Skip to content

Deprecate positional arguments for read_fwf #44710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ Other Deprecations
- Deprecated the 'errors' keyword argument in :meth:`Series.where`, :meth:`DataFrame.where`, :meth:`Series.mask`, and meth:`DataFrame.mask`; in a future version the argument will be removed (:issue:`44294`)
- Deprecated :meth:`PeriodIndex.astype` to ``datetime64[ns]`` or ``DatetimeTZDtype``, use ``obj.to_timestamp(how).tz_localize(dtype.tz)`` instead (:issue:`44398`)
- Deprecated passing non boolean argument to sort in :func:`concat` (:issue:`41518`)
- Deprecated passing arguments as positional for :func:`read_fwf` other than ``filepath_or_buffer`` (:issue:`41485`):
- Deprecated passing ``skipna=None`` for :meth:`DataFrame.mad` and :meth:`Series.mad`, pass ``skipna=True`` instead (:issue:`44580`)
- Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`)
- A deprecation warning is now shown for :meth:`DataFrame.to_latex` indicating the arguments signature may change and emulate more the arguments to :meth:`.Styler.to_latex` in future versions (:issue:`44411`)
Expand Down
3 changes: 3 additions & 0 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ def read_table(
return _read(filepath_or_buffer, kwds)


@deprecate_nonkeyword_arguments(
version=None, allowed_args=["filepath_or_buffer"], stacklevel=2
)
def read_fwf(
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
colspecs="infer",
Expand Down
14 changes: 13 additions & 1 deletion pandas/tests/io/parser/test_read_fwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_fwf_colspecs_is_list_or_tuple_of_two_element_tuples():
msg = "Each column specification must be.+"

with pytest.raises(TypeError, match=msg):
read_fwf(StringIO(data), [("a", 1)])
read_fwf(StringIO(data), colspecs=[("a", 1)])


@pytest.mark.parametrize(
Expand Down Expand Up @@ -907,3 +907,15 @@ def test_skiprows_with_iterator():
]
for i, result in enumerate(df_iter):
tm.assert_frame_equal(result, expected_frames[i])


def test_skiprows_passing_as_positional_deprecated():
# GH#41485
data = """0
1
2
"""
with tm.assert_produces_warning(FutureWarning, match="keyword-only"):
result = read_fwf(StringIO(data), [(0, 2)])
expected = DataFrame({"0": [1, 2]})
tm.assert_frame_equal(result, expected)