Skip to content
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

items method only exists in python3 #17213

Closed
tacaswell opened this issue Aug 10, 2017 · 2 comments
Closed

items method only exists in python3 #17213

tacaswell opened this issue Aug 10, 2017 · 2 comments
Milestone

Comments

@tacaswell
Copy link
Contributor

tacaswell commented Aug 10, 2017

Code Sample, a copy-pastable example if possible

for k, c in df.items():
    ...

Problem description

This works on python3 and fails on python2. This seems like a natural thing to do to have easy duck-typing between dataframes and dicts of iterables.

Either the docs should be updated to flag this as a python3 only feature or items should be shimmed onto DataFrames for all versions of python. In python2 this would have different semantics than dict.item given DataFrame has not had item before you are not changing behavior and the 'iterator-not-a-list' semantics are better.

It looks like the initial shim came in via 16dbeab .

As a side-note, six.iteritems works as expected on DataFrames.

Expected Output

it does not raise.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.13.final.0
python-bits: 64
OS: Linux
OS-release: 4.11.9-1-ARCH
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.20.3
pytest: 3.2.0
pip: 9.0.1
setuptools: 36.2.2.post20170724
Cython: None
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 5.3.0
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: None
pandas_gbq: None
pandas_datareader: None

tacaswell added a commit to tacaswell/pandas that referenced this issue Aug 10, 2017
Closes pandas-dev#17213

This leaves a slight semantic difference between `dict.items` and
`DateFrame.items` in python2, however there is no code currently
expecting `DataFrame.items` to return a list and in python3 there is
no `dict.iteritems`.

This eases writing 'native' python3 code that also runs under python2.
@gfyoung
Copy link
Member

gfyoung commented Aug 10, 2017

@tacaswell : Yeah...that's awkward. I see you've already made a commit to standardize this, which is great!

@jreback
Copy link
Contributor

jreback commented Aug 10, 2017

dupe of #13918

@jreback jreback closed this as completed Aug 10, 2017
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Aug 10, 2017
@jreback jreback added this to the No action milestone Aug 10, 2017
@gfyoung gfyoung added 2/3 Compat and removed Bug Duplicate Report Duplicate issue or pull request labels Aug 10, 2017
tacaswell added a commit to tacaswell/pandas that referenced this issue Aug 19, 2017
Closes pandas-dev#17213

This leaves a slight semantic difference between `dict.items` and
`DateFrame.items` in python2, however there is no code currently
expecting `DataFrame.items` to return a list and in python3 there is
no `dict.iteritems`.

This eases writing 'native' python3 code that also runs under python2.
@jreback jreback modified the milestones: 0.21.0, No action Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants