Skip to content

DOC: added examples for index assignment using Series #46064

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

Closed

Conversation

marco-georgaklis
Copy link

@mroeschke mroeschke added the Docs label Feb 24, 2022
@mroeschke mroeschke added this to the 1.5 milestone Feb 24, 2022
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.

LGTM. The failures are unrelated.

@@ -449,6 +449,38 @@ def loc(self) -> _LocIndexer:
8 4 5
9 7 8

**Set values with a Series**
Copy link
Contributor

Choose a reason for hiding this comment

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

this is ok but really not very idiomatic e.g. these should be on the __setitem__ doc-string e.g.
df['shield'] =

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is the docstring of .loc, that's why is using this idiom.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure but these are not idiomatic patterns for setting a column; sure if you have a mask then its the idimoatic way, but NOT for a column.

Copy link
Author

@marco-georgaklis marco-georgaklis Apr 12, 2022

Choose a reason for hiding this comment

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

Sorry, new contributor here. Where exactly should I be moving this documentation? Is it within this file (indexing.py)?

@jreback
Copy link
Contributor

jreback commented Mar 6, 2022

can you merge master

@datapythonista
Copy link
Member

@marco-georgaklis do you mind using a mask when columns are being set in this docstring so we don't show code that we wouldn't use in practice? Would be good if you can do it for the whole dosctring, not only your changes. Thanks!

@marco-georgaklis
Copy link
Author

I'm not quite sure I understand. Should I be using a mask instead of .loc when the docstring is under the .loc property?

@datapythonista
Copy link
Member

I'm not quite sure I understand. Should I be using a mask instead of .loc when the docstring is under the .loc property?

Sorry I wasn't clear. The problem with your changes, is that in pandas we don't use:

>>> df.loc[:, 'shield'] = pd.Series({7: 8, 8: 10, 9: 13})

Instead, we would use:

>>> df['shield'] = pd.Series({7: 8, 8: 10, 9: 13})

The only case where we'd use loc for setting a column, is if there is a mask (a condition on which rows should be updated. Something like:

>>> outstanding_employees = df['performance'] > 80
>>> df.loc[outstanding_employees, 'salary'] = ...

So, if you can have a look at the docstring you're updating, check if it makes sense to have an example with a mask, and update it, so the .loc[:, 'shield'] idiom is not being used, so we don't show code in the docs we wouldn't use, that would be great.

@mroeschke
Copy link
Member

Thanks for the pull request, but it appears to be stale. If interested in continuing, please merge in the main branch, address the review, and we can reopen.

@mroeschke mroeschke closed this May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Reindexing behaviour of dataframe column-assignment missing
4 participants