-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: Remove bytes input for read_excel #53830
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
Changes from 3 commits
a171b99
17353ea
5c5bdec
17ff094
a9ef371
c92a3d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
cast, | ||
overload, | ||
) | ||
import warnings | ||
import zipfile | ||
|
||
from pandas._config import config | ||
|
@@ -36,6 +37,7 @@ | |
Appender, | ||
doc, | ||
) | ||
from pandas.util._exceptions import find_stack_level | ||
from pandas.util._validators import check_dtype_backend | ||
|
||
from pandas.core.dtypes.common import ( | ||
|
@@ -97,6 +99,10 @@ | |
By file-like object, we refer to objects with a ``read()`` method, | ||
such as a file handle (e.g. via builtin ``open`` function) | ||
or ``StringIO``. | ||
|
||
.. deprecated:: 2.1.0 | ||
Passing byte strings is deprecated. To read from a " | ||
"byte string, wrap it in a `BytesIO` object. | ||
sheet_name : str, int, list, or None, default 0 | ||
Strings are used for sheet names. Integers are used in zero-indexed | ||
sheet positions (chart sheets do not count as a sheet position). | ||
|
@@ -1503,7 +1509,13 @@ def __init__( | |
|
||
# First argument can also be bytes, so create a buffer | ||
if isinstance(path_or_buffer, bytes): | ||
path_or_buffer = BytesIO(path_or_buffer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintain the current behavior during the deprecation, I think we need to continue wrapping this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yep! I added this back. Thanks for catching this! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rhshadrach I'm a bit confused on your above message 🤔 The test is passing without the line on main because the input to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test in question is
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mroeschke has been helping me with a similar problem on a few other PRs. Are you okay with it if I go ahead and take care of this discrepancy before we submit this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure the fix for this problem is just adding more input validation by using a handful of methods from common.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I think we're okay to deprecate with this PR as is, this can wait until the deprecation is enforced (i.e. the feature of reading bytes is removed in pandas 3.0). |
||
warnings.warn( | ||
"Passing bytes to 'read_excel' is deprecated and " | ||
"will be removed in a future version. To read from a " | ||
"byte string, wrap it in a `BytesIO` object.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
|
||
# Could be a str, ExcelFile, Book, etc. | ||
self.io = path_or_buffer | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the quotes (
"
), yea?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh shoot thanks! Fixed now!