Skip to content
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

DEPR: positional arguments of read/to_state #48128

Merged
merged 4 commits into from
Aug 17, 2022
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.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ Other Deprecations
- 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`)
- 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`)
- Deprecated the ``sort_columns`` argument in :meth:`DataFrame.plot` and :meth:`Series.plot` (:issue:`47563`).
- Deprecated positional arguments for all but the first argument of :meth:`DataFrame.to_stata` and :func:`read_stata`, use keyword arguments instead (:issue:`48128`).

.. ---------------------------------------------------------------------------
.. _whatsnew_150.performance:
Expand Down
1 change: 1 addition & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,7 @@ def _from_arrays(
compression_options=_shared_docs["compression_options"] % "path",
)
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "path"])
def to_stata(
self,
path: FilePath | WriteBuffer[bytes],
Expand Down
2 changes: 2 additions & 0 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
)
from pandas.util._decorators import (
Appender,
deprecate_nonkeyword_arguments,
doc,
)

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


@Appender(_read_stata_doc)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
def read_stata(
filepath_or_buffer: FilePath | ReadBuffer[bytes],
convert_dates: bool = True,
Expand Down
16 changes: 8 additions & 8 deletions pandas/tests/io/test_stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_read_write_dta5(self):
original.index.name = "index"

with tm.ensure_clean() as path:
original.to_stata(path, None)
original.to_stata(path, convert_dates=None)
written_and_read_again = self.read_dta(path)
tm.assert_frame_equal(written_and_read_again.set_index("index"), original)

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

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

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

with tm.ensure_clean() as path:
with tm.assert_produces_warning(InvalidColumnName):
original.to_stata(path, None)
original.to_stata(path, convert_dates=None)

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

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

with tm.ensure_clean() as path:
parsed_114.to_stata(path, {"date_td": "td"}, version=version)
parsed_114.to_stata(path, convert_dates={"date_td": "td"}, version=version)
written_and_read_again = self.read_dta(path)
tm.assert_frame_equal(written_and_read_again.set_index("index"), parsed_114)

Expand Down Expand Up @@ -573,7 +573,7 @@ def test_dates_invalid_column(self):
original.index.name = "index"
with tm.ensure_clean() as path:
with tm.assert_produces_warning(InvalidColumnName):
original.to_stata(path, {0: "tc"})
original.to_stata(path, convert_dates={0: "tc"})

written_and_read_again = self.read_dta(path)
modified = original.copy()
Expand Down Expand Up @@ -623,7 +623,7 @@ def test_date_export_formats(self):
expected = DataFrame([expected_values], columns=columns)
expected.index.name = "index"
with tm.ensure_clean() as path:
original.to_stata(path, conversions)
original.to_stata(path, convert_dates=conversions)
written_and_read_again = self.read_dta(path)
tm.assert_frame_equal(written_and_read_again.set_index("index"), expected)

Expand Down