Skip to content

Commit e8da6ba

Browse files
authored
DEPR: future.no_silent_downcasting (#62640)
1 parent bb18c25 commit e8da6ba

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ Other Deprecations
716716
- Deprecated using ``epoch`` date format in :meth:`DataFrame.to_json` and :meth:`Series.to_json`, use ``iso`` instead. (:issue:`57063`)
717717
- Deprecated allowing ``fill_value`` that cannot be held in the original dtype (excepting NA values for integer and bool dtypes) in :meth:`Series.unstack` and :meth:`DataFrame.unstack` (:issue:`12189`, :issue:`53868`)
718718
- Deprecated allowing ``fill_value`` that cannot be held in the original dtype (excepting NA values for integer and bool dtypes) in :meth:`Series.shift` and :meth:`DataFrame.shift` (:issue:`53802`)
719+
- Deprecated option "future.no_silent_downcasting", as it is no longer used. In a future version accessing this option will raise (:issue:`59502`)
719720
- Deprecated slicing on a :class:`Series` or :class:`DataFrame` with a :class:`DatetimeIndex` using a ``datetime.date`` object, explicitly cast to :class:`Timestamp` instead (:issue:`35830`)
720721

721722
.. ---------------------------------------------------------------------------

pandas/core/config_init.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
is_text,
2929
)
3030

31+
from pandas.errors import Pandas4Warning
32+
3133
# compute
3234

3335
use_bottleneck_doc = """
@@ -899,10 +901,10 @@ def register_converter_cb(key: str) -> None:
899901
cf.register_option(
900902
"no_silent_downcasting",
901903
False,
902-
"Whether to opt-in to the future behavior which will *not* silently "
903-
"downcast results from Series and DataFrame `where`, `mask`, and `clip` "
904-
"methods. "
905-
"Silent downcasting will be removed in pandas 3.0 "
906-
"(at which point this option will be deprecated).",
904+
"This option is deprecated and will be removed in a future version. "
905+
"It has no effect.",
907906
validator=is_one_of_factory([True, False]),
908907
)
908+
909+
# GH#59502
910+
cf.deprecate_option("future.no_silent_downcasting", Pandas4Warning)

pandas/tests/config/test_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pandas._config import config as cf
44
from pandas._config.config import OptionError
55

6+
from pandas.errors import Pandas4Warning
7+
68
import pandas as pd
79
import pandas._testing as tm
810

@@ -481,3 +483,11 @@ def test_dictwrapper_getattr(self):
481483
with pytest.raises(OptionError, match="No such option"):
482484
options.bananas
483485
assert not hasattr(options, "bananas")
486+
487+
488+
def test_no_silent_downcasting_deprecated():
489+
# GH#59502
490+
with tm.assert_produces_warning(Pandas4Warning, match="is deprecated"):
491+
cf.get_option("future.no_silent_downcasting")
492+
with tm.assert_produces_warning(Pandas4Warning, match="is deprecated"):
493+
cf.set_option("future.no_silent_downcasting", True)

pandas/tests/io/excel/test_writers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,8 +1409,7 @@ def test_render_as_column_name(self, tmp_excel):
14091409
def test_true_and_false_value_options(self, tmp_excel):
14101410
# see gh-13347
14111411
df = DataFrame([["foo", "bar"]], columns=["col1", "col2"], dtype=object)
1412-
with option_context("future.no_silent_downcasting", True):
1413-
expected = df.replace({"foo": True, "bar": False}).astype("bool")
1412+
expected = df.replace({"foo": True, "bar": False}).astype("bool")
14141413

14151414
df.to_excel(tmp_excel)
14161415
read_frame = pd.read_excel(

pandas/tests/strings/test_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
MultiIndex,
1111
Series,
1212
_testing as tm,
13-
option_context,
1413
)
1514
from pandas.core.strings.accessor import StringMethods
1615

@@ -181,8 +180,7 @@ def test_api_per_method(
181180

182181
if inferred_dtype in allowed_types:
183182
# xref GH 23555, GH 23556
184-
with option_context("future.no_silent_downcasting", True):
185-
method(*args, **kwargs) # works!
183+
method(*args, **kwargs) # works!
186184
else:
187185
# GH 23011, GH 23163
188186
msg = (

pandas/tests/strings/test_string_array.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
DataFrame,
99
Series,
1010
_testing as tm,
11-
option_context,
1211
)
1312

1413

@@ -56,8 +55,7 @@ def test_string_array(nullable_string_dtype, any_string_method):
5655
columns = expected.select_dtypes(include="object").columns
5756
assert all(result[columns].dtypes == nullable_string_dtype)
5857
result[columns] = result[columns].astype(object)
59-
with option_context("future.no_silent_downcasting", True):
60-
expected[columns] = expected[columns].fillna(NA) # GH#18463
58+
expected[columns] = expected[columns].fillna(NA) # GH#18463
6159

6260
tm.assert_equal(result, expected)
6361

0 commit comments

Comments
 (0)