Skip to content

DOC: Use of "Yields" vs "Returns" for documentation of DataFrame.items() and DataFrame.iteritems() #27860

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
benthayer opened this issue Aug 11, 2019 · 5 comments · Fixed by #27876
Labels

Comments

@benthayer
Copy link
Contributor

DataFrame.items() says it "Yields" the label and content of the columns whereas DataFrame.iteritems() says it "Returns" the label and content of the columns

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.items.html
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iteritems.html

@TomAugspurger
Copy link
Contributor

Yields is the correct one.

@jorisvandenbossche
Copy link
Member

There is some discussion about this here: #26114 (comment)

cc @topper-123

@jorisvandenbossche jorisvandenbossche changed the title Use of "Yields" vs "Returns" for documentation of DataFrame.items() and DataFrame.iteritems() DOC: Use of "Yields" vs "Returns" for documentation of DataFrame.items() and DataFrame.iteritems() Aug 12, 2019
@topper-123
Copy link
Contributor

Yeah, yield is correct, though very technically, I think items is a generator (it yields) while iteritems returns a generator (it returns something that yields).

But that is a useless distinction, so I agree both could be marked as yielding.

@benthayer
Copy link
Contributor Author

@topper-123 Not quite. When a function "yields", it is actually returning a generator object. The net effect is that both are functions and both return generators.

>>>def gen():
>>>    for i in range(100):
>>>        yield i
>>>print(type(gen))

<class 'function'>

>>>print(type(gen()))

<class 'generator'>

>>>def return_gen():
>>>    return gen()
>>>print(type(return_gen))

<class 'function'>

>>>print(type(return_gen()))

<class 'generator'>

@jorisvandenbossche
Copy link
Member

In any case, both return exactly the same:

In [8]: df = pd.DataFrame({'a': [1, 2, 3]})                                                                                                                                                   

In [9]: df.iteritems()                                                                                                                                                                        
Out[9]: <generator object DataFrame.items at 0x7f4a143e7840>

In [10]: df.items()                                                                                                                                                                           
Out[10]: <generator object DataFrame.items at 0x7f4a143e7660>

so I am not fully sure why the doc validation thinks there is a difference between both.

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 a pull request may close this issue.

4 participants