-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
removed compat check for Series.items method #13920
Conversation
can you add a test for this (see where Series.iteritems is test) |
yes would need a release note |
I wasn't sure how was best to test this (still very new to pandas development) - is this OK? |
ok this looks reasonable, ping when green. |
@@ -202,3 +202,4 @@ Bug Fixes | |||
- Bug in ``DataFrame.to_sparse()`` loses column names for MultiIndexes (:issue:`11600`) | |||
- Bug in ``DataFrame.round()`` with non-unique column index producing a Fatal Python error (:issue:`11611`) | |||
- Bug in ``DataFrame.round()`` with ``decimals`` being a non-unique indexed Series producing extra columns (:issue:`11618`) | |||
- Fixed PY2/PY3 incompatability in ``Series.items`` (:issue:`13918`) |
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.
put this in the API changes section as that will gain more attention. Say Series
has gained the .items()
method to mirror .iteritems()
and for compat with PY3 (and add for DataFrame
) as well.
It would be nice to do the same for |
be2690c
to
bdecfda
Compare
Oh yeah, sure I can add |
Current coverage is 85.26% (diff: 100%)
|
@richlewis42 Can you update this? |
Ahh sorry completely fell off my todo list. First thing tomorrow, I will finish this. |
8e406d0
to
66d57ad
Compare
@jreback This looks ready now. Is everything good? |
@@ -241,6 +241,11 @@ def test_iteritems(self): | |||
for k, v in compat.iteritems(df): | |||
self.assertEqual(type(v), Series) | |||
|
|||
def test_items(self): | |||
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b']) |
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.
add the issue number here as a comment
minorr change. lgtm. |
66d57ad
to
d6d93ba
Compare
I am concerned that |
@jreback I added the comment |
@@ -1096,8 +1096,7 @@ def iteritems(self): | |||
""" | |||
return zip(iter(self.index), iter(self)) | |||
|
|||
if compat.PY3: # pragma: no cover | |||
items = 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.
I think @shoyer is right here,; I think this will work if you do
items=compat.iteritems
which already has the correct PY2 (and 3) behavior
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 think compa.iteritems
just calls the object's iteritems
method, so that would not make a difference?
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 think @jorisvandenbossche is right - see my new comment.
@shoyer I think you are right, there is a PY2/PY3 inconsistency introduced here, and this requires more thought (sorry for leaving this around for so long, been very busy at work). How I see this: For dictionaries:
Currently in pandas for
In my opinion, PY3's Python 2>>> d = dict(a=4, b=6)
>>> d.items()
[('a', 4), ('b', 6)]
>>> d.iteritems()
<dictionary-itemiterator at 0x10bedf310>
>>> s = pd.Series(d)
>>> s.items()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-615b57d0112e> in <module>()
----> 1 s.items()
/Users/rich/anaconda/envs/python2/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
2239 or name in self._metadata
2240 or name in self._accessors):
-> 2241 return object.__getattribute__(self, name)
2242 else:
2243 if name in self._info_axis:
AttributeError: 'Series' object has no attribute 'items'
>>> s.iteritems()
<itertools.izip at 0x10bfec488>
>>> df = s.reset_index()
>>> df.items()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-952a7e29c4b1> in <module>()
----> 1 df.items()
/Users/rich/anaconda/envs/python2/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
2239 or name in self._metadata
2240 or name in self._accessors):
-> 2241 return object.__getattribute__(self, name)
2242 else:
2243 if name in self._info_axis:
AttributeError: 'DataFrame' object has no attribute 'items'
>>> df.iteritems()
<generator object iteritems at 0x10bfe96e0> Python 3>>> d = dict(a=4, b=6)
>>> d.items()
dict_items([('b', 6), ('a', 4)])
>>> d.iteritems()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-6c1b1c343924> in <module>()
----> 1 d.iteritems()
AttributeError: 'dict' object has no attribute 'iteritems'
>>> s = pd.Series(d)
>>> s.items()
<zip at 0x10686e388>
>>> s.iteritems()
<zip at 0x11e05c788>
>>> df = s.reset_index()
>>> df.items()
<generator object DataFrame.iteritems at 0x11deeb0f8>
>>> df.iteritems()
<generator object DataFrame.iteritems at 0x11dea2888> |
@richlewis42 |
can you rebase / update |
can you update |
@richlewis42 can you rebase / update. I think we do need to make a non-lazy PY2 |
Hi @jreback sorry my bad somehow wasn't getting these updates. I'll have a look as soon as I can, I'm but I'm afraid I'm writing up my PhD at the moment so really busy. |
closing as stale. please ping if you'd like to continue. |
Should I add something in the whatsnew?
I couldn't find a relevant test, so this is to check if this breaks any tests in CI.
git diff upstream/master | flake8 --diff