Skip to content

CLN Dont upcast where unnecessary (PDEP6 precursor) #52957

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

Merged
merged 1 commit into from
Apr 27, 2023
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
2 changes: 1 addition & 1 deletion doc/source/user_guide/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Building criteria

.. ipython:: python

df.loc[(df["BBB"] > 25) | (df["CCC"] >= 75), "AAA"] = 0.1
df.loc[(df["BBB"] > 25) | (df["CCC"] >= 75), "AAA"] = 999
df

`Select rows with data closest to certain value using argsort
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/missing_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ the missing value type chosen:

.. ipython:: python

s = pd.Series([1, 2, 3])
s = pd.Series([1., 2., 3.])
s.loc[0] = None
s

Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.15.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ Other notable API changes:

.. ipython:: python

s = pd.Series([1, 2, 3])
s = pd.Series([1., 2., 3.])
s.loc[0] = None
s

Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ Boolean comparisons of a ``Series`` vs ``None`` will now be equivalent to compar

.. ipython:: python

s = pd.Series(range(3))
s = pd.Series(range(3), dtype="float")
s.iloc[1] = None
s

Expand Down
24 changes: 15 additions & 9 deletions pandas/_testing/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,24 @@ def use_numexpr(use, min_elements=None) -> Generator[None, None, None]:
set_option("compute.use_numexpr", olduse)


def raises_chained_assignment_error():
if PYPY:
def raises_chained_assignment_error(extra_warnings=(), extra_match=()):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I'm giving raises_chained_assignment_error the ability to catch extra warnings (as this will be used later in #50626)

from pandas._testing import assert_produces_warning

if PYPY and not extra_warnings:
from contextlib import nullcontext

return nullcontext()
elif PYPY and extra_warnings:
return assert_produces_warning(
extra_warnings,
match="|".join(extra_match),
)
else:
from pandas._testing import assert_produces_warning

match = (
"A value is trying to be set on a copy of a DataFrame or Series "
"through chained assignment"
)
return assert_produces_warning(
ChainedAssignmentError,
match=(
"A value is trying to be set on a copy of a DataFrame or Series "
"through chained assignment"
),
(ChainedAssignmentError, *extra_warnings),
match="|".join((match, *extra_match)),
)
8 changes: 4 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7894,7 +7894,7 @@ def asof(self, where, subset=None):

Take all columns into consideration

>>> df = pd.DataFrame({'a': [10, 20, 30, 40, 50],
>>> df = pd.DataFrame({'a': [10., 20., 30., 40., 50.],
... 'b': [None, None, None, None, 500]},
... index=pd.DatetimeIndex(['2018-02-27 09:01:00',
... '2018-02-27 09:02:00',
Expand All @@ -7912,9 +7912,9 @@ def asof(self, where, subset=None):
>>> df.asof(pd.DatetimeIndex(['2018-02-27 09:03:30',
... '2018-02-27 09:04:30']),
... subset=['a'])
a b
2018-02-27 09:03:30 30 NaN
2018-02-27 09:04:30 40 NaN
a b
2018-02-27 09:03:30 30.0 NaN
2018-02-27 09:04:30 40.0 NaN
"""
if isinstance(where, str):
where = Timestamp(where)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def f_2(grp):
msg = "DataFrameGroupBy.apply operated on the grouping columns"
with tm.assert_produces_warning(FutureWarning, match=msg):
result = df.groupby("A").apply(f_2)[["B"]]
e = expected.copy()
# Explicit cast to float to avoid implicit cast when setting nan
e = expected.copy().astype({"B": "float"})
e.loc["Pony"] = np.nan
tm.assert_frame_equal(result, e)

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/groupby/test_nunique.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def check_nunique(df, keys, as_index=True):
check_nunique(frame, ["jim"])
check_nunique(frame, ["jim", "joe"])

frame = frame.astype({"julie": float}) # Explicit cast to avoid implicit cast below
frame.loc[1::17, "jim"] = None
frame.loc[3::37, "joe"] = None
frame.loc[7::19, "julie"] = None
Expand Down