-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: replace usage internally of .iteritems with .items #26114
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
Conversation
d68d4f8
to
397bf66
Compare
The error is unrelated to this PR:
|
Codecov Report
@@ Coverage Diff @@
## master #26114 +/- ##
==========================================
- Coverage 91.99% 91.97% -0.02%
==========================================
Files 175 175
Lines 52384 52392 +8
==========================================
+ Hits 48189 48190 +1
- Misses 4195 4202 +7
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26114 +/- ##
==========================================
+ Coverage 91.79% 91.86% +0.07%
==========================================
Files 180 174 -6
Lines 50934 50700 -234
==========================================
- Hits 46756 46577 -179
+ Misses 4178 4123 -55
Continue to review full report at Codecov.
|
yeah I guess we need to deprecate this. let me have a look. |
Is it needed to deprecate this? I understand it that from the stdlib python 2/3 point of view, it makes sense: However, leaving that aspect aside, from a consistency within pandas, I think having the methods |
The dict argument is also important IMO, as having DataFrames/Series be dict-like is a nice pedagogical concept, and keeping So, I think removing |
I actually like this deprecation; it clearly delineates that that we are iterating over columns, rather than the row-iterators; plus it does make sense post python 2 for more compatibility in Series with dict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on board with this one
My main problem with deprecating this is that we have consistently documented to use |
A solution to your concern could be to keep the deprecations in 0.25 in v1.0 (+ maybe 2 minor versions)? That would not be unreasonable anyway for changes so close to 1.0. Another alternative could be to make Alternatively IMO advertising DataFrames/Seried having a dict-like interface should probably be de-emphasised. E.g. the phrase here
isn't really true for Pandas on Python3 (while it was true for Pandas on Python2). |
@jorisvandenbossche AFAICT there's only a handful of references to If you feel strongly against this then something we can discuss at the sprint, but just wanted to offer that counterpoint of this I think not being too hard of a deprecation |
@topper-123 can you merge master. Conflicting files |
5d4b238
to
86c220a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comment, otherwise lgtm.
@@ -1524,10 +1524,10 @@ To iterate over the rows of a DataFrame, you can use the following methods: | |||
|
|||
df | |||
|
|||
iteritems | |||
items | |||
~~~~~~~~~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be same length as the header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
@jorisvandenbossche are you still -1 on this? |
9657a34
to
136c6c0
Compare
@topper-123 can you merge master? @jorisvandenbossche still objecting to this? |
136c6c0
to
ec3e1a2
Compare
@TomAugspurger what do you think about this? I am +0 on this, @jorisvandenbossche ? |
Maybe -0.
I don’t have a strong preference either :)
… On Jul 3, 2019, at 07:16, Jeff Reback ***@***.***> wrote:
@TomAugspurger what do you think about this? I am +0 on this, @jorisvandenbossche ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Sorry for the slow reply here. I don't feel stronly about it, so you can count me as a -0 as well (or -0.2 :-)) Basically I feel still the way as I said above (#26114 (comment)), that it feels "strange" to deprecate the method that we have always documented in favor of something that was basically not mentioned in the docs. (BTW, apart from actually deprecation, we could also already start with changing the docs) |
4fec810
to
f83f906
Compare
0de0e84
to
556dcc0
Compare
556dcc0
to
5307152
Compare
I've taken out the proposed deprecation. I would like to get the rest of the PR in though, so internally we use |
Doc-only for now sounds good.
…On Wed, Jul 10, 2019 at 6:39 AM Terji Petersen ***@***.***> wrote:
I've taken out the proposed deprecation.
I would like to get the rest of the PR in though, so internally we use
items rather than iteritems. If no one objects, I'll merge the PR in a
few days (without deprecating iteritems).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26114?email_source=notifications&email_token=AAKAOIXFJTMFXRMXSHAJ2N3P6XJ7HA5CNFSM4HGPQJ52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZTKKCQ#issuecomment-510043402>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAKAOIW6U52OV3HEQQ2XMQTP6XJ7HANCNFSM4HGPQJ5Q>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- do we need a note in whatsnew? (just saying this is now not recommended)?
- can we add a code_check to prohitbit this?
Series.items | ||
Series.iteritems |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean to add this back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as we’re not deprecating iteritems anymore?
EDIT: iteritems, not itertools....
pandas/core/frame.py
Outdated
@@ -826,6 +826,11 @@ def iteritems(self): | |||
for i, k in enumerate(self.columns): | |||
yield k, self._ixs(i, axis=1) | |||
|
|||
@Appender(items.__doc__) | |||
def iteritems(self): | |||
for key, value in self.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't want to return self.items() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I've changed that.
The issue was that items is a generator, while iteritems is a function, that returns a generator. So flake8 requires the items doc string to use "Yields" and the iteritems doc string to use "Returns".
This is a bit silly in either case, and it feels off to do stuff just to satisfy a linter.
cool thanks, ping on green. |
I can look into these two in a follow-up. |
thanks @topper-123 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify in the iteritems
docstring that it is an alias of items
, and that items
is preferred or something like that ?
if self.columns.is_unique and hasattr(self, "_item_cache"): | ||
for k in self.columns: | ||
yield k, self._get_item_cache(k) | ||
else: | ||
for i, k in enumerate(self.columns): | ||
yield k, self._ixs(i, axis=1) | ||
|
||
@Appender(_shared_docs["items"] % "Returns\n -------") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both return a generator, so why the different docstring here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the "return " part of the method that makes flake8 think this is not a generator, so it won't allow a "Yields" section in the iteritems doc string.
I think flake8 is tecnically right, but it makes for uglier code in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I think maybe if the Appender is followed by a # noqa
comment, we can make flake8 ignore that section. I'll try it tomorrow.
This is index for Series, columns for DataFrame and so on. | ||
This is index for Series and columns for DataFrame. | ||
|
||
Returns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fr the other docstring you used Yields
?
""" | ||
for h in self._info_axis: | ||
yield h, self[h] | ||
|
||
@Appender(items.__doc__) | ||
def iteritems(self): | ||
return self.items() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think both Series and DataFrame have their own implementation, so this one is nowhere used. So can rather be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into it,
git diff upstream/master -u -- "*.py" | flake8 --diff
Now that Python2 is being removed,
.iteritems
should be deprecated, and.items
should be used instead.EDIT: This PR ended up not deprecating .iteritems, but only change its usage internally with using .items