Skip to content

DOC: Note itertuples created with rename=True #50836

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
2 of 3 tasks
snowman2 opened this issue Jan 18, 2023 · 5 comments
Closed
2 of 3 tasks

DOC: Note itertuples created with rename=True #50836

snowman2 opened this issue Jan 18, 2023 · 5 comments
Labels

Comments

@snowman2
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

>>> import pandas
>>> pdf = pandas.DataFrame({"yield": [1, 2]})
>>> pdf
   yield
0      1
1      2
>>> item = next(pdf.itertuples())
>>> item
Pandas(Index=0, _1=1)

Issue Description

The column named "yield" is renamed in itertuples.

Expected Behavior

The column name remains unchanged.

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.9.15.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-58-generic
Version : #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.2
numpy : 1.23.5
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 66.0.0
pip : 22.3.1
Cython : None
pytest : 7.2.1
hypothesis : None
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 8.8.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : 2022.11.0
gcsfs : None
matplotlib : 3.6.2
numba : 0.56.4
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2022.11.0
scipy : 1.10.0
snappy : None
sqlalchemy : 1.4.46
tables : None
tabulate : 0.9.0
xarray : 2022.12.0
xlrd : None
xlwt : None
zstandard : None
tzdata : 2022.7

@snowman2 snowman2 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 18, 2023
@mroeschke
Copy link
Member

This is as intended as the namedtuples are generated with rename=True: https://docs.python.org/3/library/collections.html#collections.namedtuple

And this is tested in test_itertuples

This could be better documented

@mroeschke mroeschke added Docs and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 18, 2023
@mroeschke mroeschke changed the title BUG: yield column renamed with itertuples DOC: Note itertuples created with rename=True Jan 18, 2023
@mroeschke
Copy link
Member

Oh actually this is documented in the docstring

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

The column names will be renamed to positional names if they are invalid Python identifiers, repeated, or start with an underscore.

Therefore closing

@snowman2
Copy link
Author

Thanks 👍

@snowman2
Copy link
Author

Might not be bad to add a reference to this: https://realpython.com/python-keywords/

@snowman2
Copy link
Author

Or at least this: https://docs.python.org/3/library/keyword.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants