Skip to content

DOC: ExcelWriter constructor types #35505

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
alexhtn opened this issue Aug 1, 2020 · 12 comments · Fixed by #35568
Closed

DOC: ExcelWriter constructor types #35505

alexhtn opened this issue Aug 1, 2020 · 12 comments · Fixed by #35568
Assignees
Labels
Docs IO Excel read_excel, to_excel
Milestone

Comments

@alexhtn
Copy link
Contributor

alexhtn commented Aug 1, 2020

Location of the documentation

https://pandas.pydata.org/docs/dev/reference/api/pandas.ExcelWriter.html?highlight=excelwriter
or

path : str

Documentation problem

Parameter path has type str, but based on this feature https://github.com/pandas-dev/pandas/issues/7074 I can pass io.BytesIO.

Suggested fix for documentation

Change type description to str | io.BytesIO.

@alexhtn alexhtn added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 1, 2020
@rhshadrach
Copy link
Member

The links in the issue are broken, you need to use

[description](url)

@MJafarMashhadi
Copy link
Contributor

It's better to use bytes-like object instead of io.BytesIO specifically.

@alexhtn alexhtn changed the title DOC: DOC: ExcelWriter constructor types Aug 1, 2020
@alexhtn
Copy link
Contributor Author

alexhtn commented Aug 1, 2020

The links in the issue are broken, you need to use

I fixed links

@alexhtn
Copy link
Contributor Author

alexhtn commented Aug 1, 2020

It's better to use bytes-like object instead of io.BytesIO specifically.

I didn't understand how can I use bytes-like object as output for ExcelWriter.

@MJafarMashhadi
Copy link
Contributor

I mean it doesn't strictly require io.BytesIO instance, it can be a subclass or anything else that behaves like a bytes buffer (a zip file, a network socket, etc). So I'd suggest to use a more generic term in your patch.

with zipfile.ZipFile('samplezip.zip', 'w') as zf:
    with zf.open('XLfile.xlsx', 'w') as inf:
        with ExcelWriter(inf) as ew:
            df.to_excel(ew)

@alexhtn
Copy link
Contributor Author

alexhtn commented Aug 1, 2020

Now I got your idea.
I think correct type is io.BufferedIOBase. ZipFile and io.Bytes inherits from it, and function open returns io.BufferedWriter.
Also I check socket.makefile, for binary format in writing mode it returns io.BufferedWriter.
io.BufferedWriter inherits from io.BufferedIOBase.
But I'm not sure that it covers all cases. Maybe correct type would be io.IOBase.

@MJafarMashhadi
Copy link
Contributor

I believe bytes like object means the same thing. It's more about having the expected interface (duck typing), rather than being a subclass of a certain class (which is the case in Java).

@alexhtn
Copy link
Contributor Author

alexhtn commented Aug 2, 2020

I understand this. But now possibility of using bytes-likes objects isn't described in docs at all and also pycharm shows warnings.
I think it would be enough add io.BufferedIOBase to path type and some examples to show how it works.

@MJafarMashhadi
Copy link
Contributor

Sounds good, Would you like to submit a PR?

@AlexKirko AlexKirko added IO Excel read_excel, to_excel and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 3, 2020
@alexhtn
Copy link
Contributor Author

alexhtn commented Aug 3, 2020

take

@alexhtn
Copy link
Contributor Author

alexhtn commented Aug 4, 2020

After I made changes to docstring I ran python scripts/validate_docstrings.py pandas.ExcelWriter and it showed errors for new examples and also for old examples: NameError: name 'ExcelWriter' is not defined and NameError: name 'df' is not defined.
Should I ignore these errors?

@MJafarMashhadi
Copy link
Contributor

The current version has that warning anyway, so I guess you can ignore that. Worst case, you'll get a comment in code review on how to fix it.

alexhtn added a commit to alexhtn/pandas that referenced this issue Aug 5, 2020
alexhtn added a commit to alexhtn/pandas that referenced this issue Aug 24, 2020
@jreback jreback added this to the 1.2 milestone Sep 13, 2020
kesmit13 pushed a commit to kesmit13/pandas that referenced this issue Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants