Skip to content

Commit 08c688d

Browse files
authored
Deprecate positional arguments for read_fwf (#44710)
1 parent 328e5b6 commit 08c688d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ Other Deprecations
519519
- 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`)
520520
- Deprecated :meth:`PeriodIndex.astype` to ``datetime64[ns]`` or ``DatetimeTZDtype``, use ``obj.to_timestamp(how).tz_localize(dtype.tz)`` instead (:issue:`44398`)
521521
- Deprecated passing non boolean argument to sort in :func:`concat` (:issue:`41518`)
522+
- Deprecated passing arguments as positional for :func:`read_fwf` other than ``filepath_or_buffer`` (:issue:`41485`):
522523
- Deprecated passing ``skipna=None`` for :meth:`DataFrame.mad` and :meth:`Series.mad`, pass ``skipna=True`` instead (:issue:`44580`)
523524
- Deprecated :meth:`DateOffset.apply`, use ``offset + other`` instead (:issue:`44522`)
524525
- 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`)

pandas/io/parsers/readers.py

+3
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,9 @@ def read_table(
758758
return _read(filepath_or_buffer, kwds)
759759

760760

761+
@deprecate_nonkeyword_arguments(
762+
version=None, allowed_args=["filepath_or_buffer"], stacklevel=2
763+
)
761764
def read_fwf(
762765
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
763766
colspecs: list[tuple[int, int]] | str | None = "infer",

pandas/tests/io/parser/test_read_fwf.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_fwf_colspecs_is_list_or_tuple_of_two_element_tuples():
218218
msg = "Each column specification must be.+"
219219

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

223223

224224
@pytest.mark.parametrize(
@@ -907,3 +907,15 @@ def test_skiprows_with_iterator():
907907
]
908908
for i, result in enumerate(df_iter):
909909
tm.assert_frame_equal(result, expected_frames[i])
910+
911+
912+
def test_skiprows_passing_as_positional_deprecated():
913+
# GH#41485
914+
data = """0
915+
1
916+
2
917+
"""
918+
with tm.assert_produces_warning(FutureWarning, match="keyword-only"):
919+
result = read_fwf(StringIO(data), [(0, 2)])
920+
expected = DataFrame({"0": [1, 2]})
921+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)