Skip to content

BUG raise pdep6 warning for loc full setter #56146

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 47 commits into from
Jan 9, 2024

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Nov 24, 2023

@mroeschke mroeschke added the PDEP6-related related to PDEP6 (not upcasting during setitem-like Series operations) label Nov 27, 2023
@MarcoGorelli MarcoGorelli mentioned this pull request Nov 27, 2023
@MarcoGorelli
Copy link
Member Author

thanks for your reviews! have updated

@@ -584,6 +584,7 @@ Conversion
- Bug in :meth:`DataFrame.astype` when called with ``str`` on unpickled array - the array might change in-place (:issue:`54654`)
- Bug in :meth:`DataFrame.astype` where ``errors="ignore"`` had no effect for extension types (:issue:`54654`)
- Bug in :meth:`Series.convert_dtypes` not converting all NA column to ``null[pyarrow]`` (:issue:`55346`)
- Bug in ``DataFrame.loc`` was not throwing "incompatible dtype warning" (see PDEP6) when assigning a ``Series`` with a different dtype using a full column setter (e.g. ``df.loc[:, 'a'] = incompatible_value``) (:issue:`39584`)
Copy link
Member

Choose a reason for hiding this comment

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

should "PDEP6" here get some type of colons or backticks or something to become a link? (i dont care that much)

@@ -498,6 +498,9 @@ def coerce_to_target_dtype(self, other, warn_on_upcast: bool = False) -> Block:
and is_integer_dtype(self.values.dtype)
and isna(other)
and other is not NaT
and not (
isinstance(other, (np.datetime64, np.timedelta64)) and np.isnat(other)
Copy link
Member

Choose a reason for hiding this comment

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

i think the isnat here is unnecessary since we already have isna(other) above

Copy link
Member Author

Choose a reason for hiding this comment

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

the idea of the this if statement is to check whether self is of integer type, and other is of a type that it will be possible, in the future, to set into self without having to coerce self

This is the case if other is nan or NA, but presumably we still want to raise if someone tries setting NaT? If so, then this check if looking for cases when isna(other) is True but other was not NaT - that's why I don't think the isnat check is unnecessary

@@ -199,7 +199,7 @@ def f_1(grp):
with tm.assert_produces_warning(FutureWarning, match=msg):
result = df.groupby("A").apply(f_1)[["B"]]
e = expected.copy()
e.loc["Tiger"] = np.nan
e["B"] = [3, 5, float("nan")]
Copy link
Member

Choose a reason for hiding this comment

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

why is this changing? any reason for float('nan') instead of np.nan?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, it didn't need to change, thanks

@@ -491,7 +491,7 @@ def _check_setitem_invalid(self, ser, invalid, indexer, warn):
np.datetime64("NaT"),
np.timedelta64("NaT"),
]
_indexers = [0, [0], slice(0, 1), [True, False, False]]
_indexers = [0, [0], slice(0, 1), [True, False, False], slice(None, None, None)]
Copy link
Member

Choose a reason for hiding this comment

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

this looks similar to the DataFrame test above. lets try to de-duplicate it one of these days

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

@phofl phofl merged commit fce520d into pandas-dev:main Jan 9, 2024
@phofl
Copy link
Member

phofl commented Jan 9, 2024

thx @MarcoGorelli

@phofl phofl added this to the 2.2 milestone Jan 9, 2024
@phofl
Copy link
Member

phofl commented Jan 9, 2024

@meeseeksdev backport 2.2.x

Copy link

lumberbot-app bot commented Jan 9, 2024

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 2.2.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 fce520d45a304ee2659bb4156acf484cee5aea07
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #56146: BUG raise pdep6 warning for loc full setter'
  1. Push to a named branch:
git push YOURFORK 2.2.x:auto-backport-of-pr-56146-on-2.2.x
  1. Create a PR against branch 2.2.x, I would have named this PR:

"Backport PR #56146 on branch 2.2.x (BUG raise pdep6 warning for loc full setter)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@phofl
Copy link
Member

phofl commented Jan 9, 2024

@MarcoGorelli could you take care of the backport?

@MarcoGorelli
Copy link
Member Author

Yup will do in the morning, thanks!

MarcoGorelli added a commit to MarcoGorelli/pandas that referenced this pull request Jan 10, 2024
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PDEP6-related related to PDEP6 (not upcasting during setitem-like Series operations)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants