Skip to content

Commit 5d115fd

Browse files
committed
Merge branch 'main' into bug-decimal
2 parents 3aaaa53 + 066a4f7 commit 5d115fd

File tree

9 files changed

+49
-18
lines changed

9 files changed

+49
-18
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 1 deletion
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
.. ---------------------------------------------------------------------------
@@ -1016,8 +1017,8 @@ Strings
10161017
Interval
10171018
^^^^^^^^
10181019
- :meth:`Index.is_monotonic_decreasing`, :meth:`Index.is_monotonic_increasing`, and :meth:`Index.is_unique` could incorrectly be ``False`` for an ``Index`` created from a slice of another ``Index``. (:issue:`57911`)
1020+
- Bug in :class:`Index`, :class:`Series`, :class:`DataFrame` constructors when given a sequence of :class:`Interval` subclass objects casting them to :class:`Interval` (:issue:`46945`)
10191021
- Bug in :func:`interval_range` where start and end numeric types were always cast to 64 bit (:issue:`57268`)
1020-
-
10211022

10221023
Indexing
10231024
^^^^^^^^

pandas/_libs/lib.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,8 @@ cpdef bint is_interval_array(ndarray values):
22552255
for i in range(n):
22562256
val = values[i]
22572257

2258-
if isinstance(val, Interval):
2258+
if type(val) is Interval:
2259+
# GH#46945 catch Interval exactly, excluding subclasses
22592260
if closed is None:
22602261
closed = val.closed
22612262
numeric = (

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/dtypes/test_inference.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,24 @@ def test_is_string_array(self):
16051605
)
16061606
assert not lib.is_string_array(np.array([1, 2]))
16071607

1608+
def test_is_interval_array_subclass(self):
1609+
# GH#46945
1610+
1611+
class TimestampsInterval(Interval):
1612+
def __init__(self, left: str, right: str, closed="both") -> None:
1613+
super().__init__(Timestamp(left), Timestamp(right), closed)
1614+
1615+
@property
1616+
def seconds(self) -> float:
1617+
return self.length.seconds
1618+
1619+
item = TimestampsInterval("1970-01-01 00:00:00", "1970-01-01 00:00:01")
1620+
arr = np.array([item], dtype=object)
1621+
assert not lib.is_interval_array(arr)
1622+
assert lib.infer_dtype(arr) != "interval"
1623+
out = Series([item])[0]
1624+
assert isinstance(out, TimestampsInterval)
1625+
16081626
@pytest.mark.parametrize(
16091627
"func",
16101628
[

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/io/test_parquet.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def check_round_trip(
198198
repeat: int, optional
199199
How many times to repeat the test
200200
"""
201+
if not isinstance(temp_file, pathlib.Path):
202+
raise ValueError("temp_file must be a pathlib.Path")
201203
write_kwargs = write_kwargs or {"compression": None}
202204
read_kwargs = read_kwargs or {}
203205

@@ -396,9 +398,11 @@ def test_columns_dtypes(self, engine, temp_file):
396398
check_round_trip(df, temp_file, engine)
397399

398400
@pytest.mark.parametrize("compression", [None, "gzip", "snappy", "brotli"])
399-
def test_compression(self, engine, compression):
401+
def test_compression(self, engine, compression, temp_file):
400402
df = pd.DataFrame({"A": [1, 2, 3]})
401-
check_round_trip(df, engine, write_kwargs={"compression": compression})
403+
check_round_trip(
404+
df, temp_file, engine, write_kwargs={"compression": compression}
405+
)
402406

403407
def test_read_columns(self, engine, temp_file):
404408
# GH18154
@@ -424,8 +428,8 @@ def test_read_filters(self, engine, tmp_path):
424428
expected = pd.DataFrame({"int": [0, 1]})
425429
check_round_trip(
426430
df,
431+
tmp_path,
427432
engine,
428-
path=tmp_path,
429433
expected=expected,
430434
write_kwargs={"partition_cols": ["part"]},
431435
read_kwargs={"filters": [("part", "==", "a")], "columns": ["int"]},

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)