Skip to content

Commit 5ad44e7

Browse files
authored
DEPR: positional arguments of read/to_state (#48128)
* DEPR: positional arguments of read/to_state * pr number * isort * use keyword arguments in tests and fix typo
1 parent a6aaeb6 commit 5ad44e7

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ Other Deprecations
850850
- Deprecated producing a single element when iterating over a :class:`DataFrameGroupBy` or a :class:`SeriesGroupBy` that has been grouped by a list of length 1; A tuple of length one will be returned instead (:issue:`42795`)
851851
- Fixed up warning message of deprecation of :meth:`MultiIndex.lesort_depth` as public method, as the message previously referred to :meth:`MultiIndex.is_lexsorted` instead (:issue:`38701`)
852852
- Deprecated the ``sort_columns`` argument in :meth:`DataFrame.plot` and :meth:`Series.plot` (:issue:`47563`).
853+
- Deprecated positional arguments for all but the first argument of :meth:`DataFrame.to_stata` and :func:`read_stata`, use keyword arguments instead (:issue:`48128`).
853854

854855
.. ---------------------------------------------------------------------------
855856
.. _whatsnew_150.performance:

pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,7 @@ def _from_arrays(
25762576
compression_options=_shared_docs["compression_options"] % "path",
25772577
)
25782578
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
2579+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "path"])
25792580
def to_stata(
25802581
self,
25812582
path: FilePath | WriteBuffer[bytes],

pandas/io/stata.py

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
)
5050
from pandas.util._decorators import (
5151
Appender,
52+
deprecate_nonkeyword_arguments,
5253
doc,
5354
)
5455

@@ -1980,6 +1981,7 @@ def value_labels(self) -> dict[str, dict[float, str]]:
19801981

19811982

19821983
@Appender(_read_stata_doc)
1984+
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
19831985
def read_stata(
19841986
filepath_or_buffer: FilePath | ReadBuffer[bytes],
19851987
convert_dates: bool = True,

pandas/tests/io/test_stata.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_read_write_dta5(self):
285285
original.index.name = "index"
286286

287287
with tm.ensure_clean() as path:
288-
original.to_stata(path, None)
288+
original.to_stata(path, convert_dates=None)
289289
written_and_read_again = self.read_dta(path)
290290
tm.assert_frame_equal(written_and_read_again.set_index("index"), original)
291291

@@ -297,7 +297,7 @@ def test_write_dta6(self, datapath):
297297
original["quarter"] = original["quarter"].astype(np.int32)
298298

299299
with tm.ensure_clean() as path:
300-
original.to_stata(path, None)
300+
original.to_stata(path, convert_dates=None)
301301
written_and_read_again = self.read_dta(path)
302302
tm.assert_frame_equal(
303303
written_and_read_again.set_index("index"),
@@ -317,7 +317,7 @@ def test_read_write_dta10(self, version):
317317
original["integer"] = original["integer"].astype(np.int32)
318318

319319
with tm.ensure_clean() as path:
320-
original.to_stata(path, {"datetime": "tc"}, version=version)
320+
original.to_stata(path, convert_dates={"datetime": "tc"}, version=version)
321321
written_and_read_again = self.read_dta(path)
322322
# original.index is np.int32, read index is np.int64
323323
tm.assert_frame_equal(
@@ -377,7 +377,7 @@ def test_read_write_dta11(self):
377377

378378
with tm.ensure_clean() as path:
379379
with tm.assert_produces_warning(InvalidColumnName):
380-
original.to_stata(path, None)
380+
original.to_stata(path, convert_dates=None)
381381

382382
written_and_read_again = self.read_dta(path)
383383
tm.assert_frame_equal(written_and_read_again.set_index("index"), formatted)
@@ -412,7 +412,7 @@ def test_read_write_dta12(self, version):
412412
with tm.ensure_clean() as path:
413413
with warnings.catch_warnings(record=True) as w:
414414
warnings.simplefilter("always", InvalidColumnName)
415-
original.to_stata(path, None, version=version)
415+
original.to_stata(path, convert_dates=None, version=version)
416416
# should get a warning for that format.
417417
assert len(w) == 1
418418

@@ -453,7 +453,7 @@ def test_read_write_reread_dta14(self, file, parsed_114, version, datapath):
453453
tm.assert_frame_equal(parsed_114, parsed)
454454

455455
with tm.ensure_clean() as path:
456-
parsed_114.to_stata(path, {"date_td": "td"}, version=version)
456+
parsed_114.to_stata(path, convert_dates={"date_td": "td"}, version=version)
457457
written_and_read_again = self.read_dta(path)
458458
tm.assert_frame_equal(written_and_read_again.set_index("index"), parsed_114)
459459

@@ -573,7 +573,7 @@ def test_dates_invalid_column(self):
573573
original.index.name = "index"
574574
with tm.ensure_clean() as path:
575575
with tm.assert_produces_warning(InvalidColumnName):
576-
original.to_stata(path, {0: "tc"})
576+
original.to_stata(path, convert_dates={0: "tc"})
577577

578578
written_and_read_again = self.read_dta(path)
579579
modified = original.copy()
@@ -623,7 +623,7 @@ def test_date_export_formats(self):
623623
expected = DataFrame([expected_values], columns=columns)
624624
expected.index.name = "index"
625625
with tm.ensure_clean() as path:
626-
original.to_stata(path, conversions)
626+
original.to_stata(path, convert_dates=conversions)
627627
written_and_read_again = self.read_dta(path)
628628
tm.assert_frame_equal(written_and_read_again.set_index("index"), expected)
629629

0 commit comments

Comments
 (0)