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

Pandas.items in Python2 vs Python3 #13918

Closed
richlewis42 opened this Issue Aug 5, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@richlewis42
Contributor

richlewis42 commented Aug 5, 2016

Inconsistency between python2 and 3 - python2 has no items method (but does have iteritems). Shouldn't items and iteritems be the same?

Code Sample, a copy-pastable example if possible

import pandas as pd
import string
ser = pd.Series(np.arange(10), index=list(string.ascii_letters[:10]))
print(ser.items())

Expected Output

<zip object at 0x11dc1f6c8>

python 2:
AttributeError: 'Series' object has no attribute 'items'

output of pd.show_versions() (python2)

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 15.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8

pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 23.0.0
Cython: None
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 5.0.0
sphinx: None
patsy: None
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.5.2
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Aug 5, 2016

Contributor

Series has never had an .items method IIRC, which by-definition is NOT lazy. So I suppose this could be added for compat (as PY3 DOES have an .items method).

Contributor

jreback commented Aug 5, 2016

Series has never had an .items method IIRC, which by-definition is NOT lazy. So I suppose this could be added for compat (as PY3 DOES have an .items method).

@jreback jreback added the 2/3 Compat label Aug 5, 2016

@jreback jreback added this to the Next Major Release milestone Aug 5, 2016

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Aug 5, 2016

Contributor

if you want to submit a PR and see if anything breaks that would be great.

Contributor

jreback commented Aug 5, 2016

if you want to submit a PR and see if anything breaks that would be great.

@richlewis42

This comment has been minimized.

Show comment
Hide comment
@richlewis42

richlewis42 Aug 5, 2016

Contributor

I thought .items (at least for dict) was lazy in 3 and not in 2 (iteritems doesn't exist in 3).

The implementation is currently:

class Series(...
    def iteritems(self):
        """
        Lazily iterate over (index, value) tuples
        """
        return zip(iter(self.index), iter(self))

    if compat.PY3:  # pragma: no cover
        items = iteritems

I would simply propose removing the compat check (or not having it at all).

Contributor

richlewis42 commented Aug 5, 2016

I thought .items (at least for dict) was lazy in 3 and not in 2 (iteritems doesn't exist in 3).

The implementation is currently:

class Series(...
    def iteritems(self):
        """
        Lazily iterate over (index, value) tuples
        """
        return zip(iter(self.index), iter(self))

    if compat.PY3:  # pragma: no cover
        items = iteritems

I would simply propose removing the compat check (or not having it at all).

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Aug 5, 2016

Contributor

@richlewis42 as I said, you can try removing it and see what happens (you prob also need to fix a test)

Contributor

jreback commented Aug 5, 2016

@richlewis42 as I said, you can try removing it and see what happens (you prob also need to fix a test)

@shoyer

This comment has been minimized.

Show comment
Hide comment
@shoyer

shoyer Aug 5, 2016

Member

This seems like a good idea to me. Can we do the same for DataFrame.items as well?

Member

shoyer commented Aug 5, 2016

This seems like a good idea to me. Can we do the same for DataFrame.items as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment