Skip to content

BUG: AttributeError: 'TextFileReader' object has no attribute 'f' #46187

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

Open
3 tasks done
theinexorable opened this issue Feb 28, 2022 · 4 comments
Open
3 tasks done
Labels
Docs IO CSV read_csv, to_csv

Comments

@theinexorable
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 as pd
file = 'random.csv'
chunks = pd.read_csv(file, chunksize=n)
name = chunks.f.rsplit('.', 1)[0]

Issue Description

TextFileReader object no more has .f attribute, containing the name of the given file.
I can't find in the changelog of 1.4.1 this deprecation.

Expected Behavior

.f or other attribute to keep the file name. Helpful to implement in a function to create multiple same-name export files.

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.9.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : AMD64 Family 23 Model 1 Stepping 1, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : en
LOCALE : Bulgarian_Bulgaria.1251

pandas : 1.4.1
numpy : 1.20.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.25
pytest : 6.2.5
hypothesis : None
sphinx : 4.4.0
blosc : None
feather : None
xlsxwriter : 3.0.2
lxml.etree : 4.7.1
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.31.1
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fastparquet : None
fsspec : 2022.01.0
gcsfs : None
matplotlib : 3.5.1
numba : 0.54.1
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 4.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.27
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
zstandard : None

@theinexorable theinexorable added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 28, 2022
@theinexorable
Copy link
Author

so i found out it was in https://github.com/pandas-dev/pandas/blob/v1.3.5/pandas/io/parsers/readers.py
line 774 within class TextFileReader(abc.Iterator):
self.f = f
question is why remove and can I get the name out of some other attribute?

@twoertwein
Copy link
Member

Was f ever documented to be public? If not, it was (meant) to be private.

Also, f does not need to be a string, it can be a file-like object.

@phofl
Copy link
Member

phofl commented Mar 1, 2022

I don‘t know if TextFileReader is documented at all

@twoertwein twoertwein added the Docs label Mar 2, 2022
@twoertwein
Copy link
Member

At the very least, we should have a doc-page about TextFileReader that says that only __next__, __enter__, and __exit__ are supposed to be used (for-loop and context manager). Maybe also add more methods/attributes if there are common use-cases.

@lithomas1 lithomas1 added IO CSV read_csv, to_csv and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 3, 2022
@jreback jreback added this to the 1.5 milestone Mar 11, 2022
@mroeschke mroeschke removed this from the 1.5 milestone Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants