-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: Remove literal string input for read_xml #53809
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 8 commits
f347e8e
296b45a
69cdc1a
83a9177
0f0f38b
2c848ac
b8a582c
92bc6fa
8bbd7c4
5aece78
6f15924
00f7b15
20e7ef2
526c224
9dfa18d
65f88b9
ec28efa
2c58638
e08f4e0
ba1edd6
b7e1fb6
14d2cb1
c215a94
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
Callable, | ||
Sequence, | ||
) | ||
import warnings | ||
|
||
from pandas._libs import lib | ||
from pandas.compat._optional import import_optional_dependency | ||
|
@@ -20,6 +21,7 @@ | |
ParserError, | ||
) | ||
from pandas.util._decorators import doc | ||
from pandas.util._exceptions import find_stack_level | ||
from pandas.util._validators import check_dtype_backend | ||
|
||
from pandas.core.dtypes.common import is_list_like | ||
|
@@ -894,6 +896,9 @@ def read_xml( | |
string or a path. The string can further be a URL. Valid URL schemes | ||
include http, ftp, s3, and file. | ||
|
||
.. deprecated:: 2.1.0 | ||
Passing html literal strings is deprecated. | ||
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. Could you mention wrapping in |
||
|
||
xpath : str, optional, default './\*' | ||
The XPath to parse required set of nodes for migration to DataFrame. | ||
XPath should return a collection of elements and not a single | ||
|
@@ -1049,6 +1054,7 @@ def read_xml( | |
|
||
Examples | ||
-------- | ||
>>> import io | ||
>>> xml = '''<?xml version='1.0' encoding='utf-8'?> | ||
... <data xmlns="http://example.com"> | ||
... <row> | ||
|
@@ -1068,7 +1074,7 @@ def read_xml( | |
... </row> | ||
... </data>''' | ||
|
||
>>> df = pd.read_xml(xml) | ||
>>> df = pd.read_xml(io.StringIO(xml)) | ||
>>> df | ||
shape degrees sides | ||
0 square 360 4.0 | ||
|
@@ -1082,7 +1088,7 @@ def read_xml( | |
... <row shape="triangle" degrees="180" sides="3.0"/> | ||
... </data>''' | ||
|
||
>>> df = pd.read_xml(xml, xpath=".//row") | ||
>>> df = pd.read_xml(io.StringIO(xml), xpath=".//row") | ||
>>> df | ||
shape degrees sides | ||
0 square 360 4.0 | ||
|
@@ -1108,7 +1114,7 @@ def read_xml( | |
... </doc:row> | ||
... </doc:data>''' | ||
|
||
>>> df = pd.read_xml(xml, | ||
>>> df = pd.read_xml(io.StringIO(xml), | ||
... xpath="//doc:row", | ||
... namespaces={{"doc": "https://example.com"}}) | ||
>>> df | ||
|
@@ -1119,6 +1125,15 @@ def read_xml( | |
""" | ||
check_dtype_backend(dtype_backend) | ||
|
||
if isinstance(path_or_buffer, str) and "\n" in 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. 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. I think you can use 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 Ah thanks for letting me know about Are we okay with updating the detection logic to include both 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. You can use |
||
warnings.warn( | ||
"Passing literal xml to 'read_xml' is deprecated and " | ||
"will be removed in a future version. To read from a " | ||
"literal string, wrap it in a 'StringIO' object.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
|
||
return _parse( | ||
path_or_buffer=path_or_buffer, | ||
xpath=xpath, | ||
|
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.