|
61 | 61 | IndexLabel,
|
62 | 62 | StorageOptions,
|
63 | 63 | )
|
64 |
| -from pandas.compat._optional import import_optional_dependency |
65 |
| -from pandas.util._decorators import doc |
66 | 64 |
|
67 | 65 | from pandas.core.dtypes.common import (
|
68 | 66 | is_categorical_dtype,
|
|
98 | 96 | from pandas.core.indexes.datetimes import DatetimeIndex
|
99 | 97 | from pandas.core.indexes.timedeltas import TimedeltaIndex
|
100 | 98 | from pandas.core.reshape.concat import concat
|
101 |
| -from pandas.core.shared_docs import _shared_docs |
102 | 99 |
|
103 | 100 | from pandas.io.common import stringify_path
|
104 | 101 | from pandas.io.formats.printing import (
|
@@ -944,7 +941,6 @@ class DataFrameRenderer:
|
944 | 941 |
|
945 | 942 | Called in pandas.core.frame.DataFrame:
|
946 | 943 | - to_html
|
947 |
| - - to_xml |
948 | 944 | - to_string
|
949 | 945 |
|
950 | 946 | Parameters
|
@@ -1037,135 +1033,6 @@ def to_html(
|
1037 | 1033 | string = html_formatter.to_string()
|
1038 | 1034 | return save_to_buffer(string, buf=buf, encoding=encoding)
|
1039 | 1035 |
|
1040 |
| - @doc(storage_options=_shared_docs["storage_options"]) |
1041 |
| - def to_xml( |
1042 |
| - self, |
1043 |
| - path_or_buffer: Optional[FilePathOrBuffer] = None, |
1044 |
| - index: Optional[bool] = True, |
1045 |
| - root_name: Optional[str] = "data", |
1046 |
| - row_name: Optional[str] = "row", |
1047 |
| - na_rep: Optional[str] = None, |
1048 |
| - attr_cols: Optional[Union[str, List[str]]] = None, |
1049 |
| - elem_cols: Optional[Union[str, List[str]]] = None, |
1050 |
| - namespaces: Optional[Dict[Optional[str], str]] = None, |
1051 |
| - prefix: Optional[str] = None, |
1052 |
| - encoding: str = "utf-8", |
1053 |
| - xml_declaration: Optional[bool] = True, |
1054 |
| - pretty_print: Optional[bool] = True, |
1055 |
| - parser: Optional[str] = "lxml", |
1056 |
| - stylesheet: Optional[FilePathOrBuffer] = None, |
1057 |
| - compression: CompressionOptions = "infer", |
1058 |
| - storage_options: StorageOptions = None, |
1059 |
| - ) -> Optional[str]: |
1060 |
| - """ |
1061 |
| - Render a DataFrame to an XML document. |
1062 |
| -
|
1063 |
| - .. versionadded:: 1.3.0 |
1064 |
| -
|
1065 |
| - Parameters |
1066 |
| - ---------- |
1067 |
| - path_or_buffer : str, path object or file-like object, optional |
1068 |
| - File to write output to. If None, the output is returned as a |
1069 |
| - string. |
1070 |
| - index : bool, default True |
1071 |
| - Whether to include index in XML document. |
1072 |
| - root_name : str, default 'data' |
1073 |
| - The name of root element in XML document. |
1074 |
| - row_name : str, default 'row' |
1075 |
| - The name of row element in XML document. |
1076 |
| - na_rep : str, optional |
1077 |
| - Missing data representation. |
1078 |
| - attr_cols : list-like, optional |
1079 |
| - List of columns to write as attributes in row element. |
1080 |
| - Hierarchical columns will be flattened with underscore |
1081 |
| - delimiting the different levels. |
1082 |
| - elem_cols : list-like, optional |
1083 |
| - List of columns to write as children in row element. By default, |
1084 |
| - all columns output as children of row element. Hierarchical |
1085 |
| - columns will be flattened with underscore delimiting the |
1086 |
| - different levels. |
1087 |
| - namespaces : dict, optional |
1088 |
| - All namespaces to be defined in root element. Keys of dict |
1089 |
| - should be prefix names and values of dict corresponding URIs. |
1090 |
| - Default namespaces should be given empty string key. For |
1091 |
| - example, :: |
1092 |
| -
|
1093 |
| - namespaces = {{'': 'https://example.com'}} |
1094 |
| -
|
1095 |
| - prefix : str, optional |
1096 |
| - Namespace prefix to be used for every element and/or attribute |
1097 |
| - in document. This should be one of the keys in ``namespaces`` |
1098 |
| - dict. |
1099 |
| - encoding : str, default 'utf-8' |
1100 |
| - Encoding of the resulting document. |
1101 |
| - xml_declaration : str, optional |
1102 |
| - Whether to include the XML declaration at start of document. |
1103 |
| - pretty_print : bool, default True |
1104 |
| - Whether output should be pretty printed with indentation and |
1105 |
| - line breaks. |
1106 |
| - parser : {{'lxml','etree'}}, default "lxml" |
1107 |
| - Parser module to use for building of tree. Only 'lxml' and |
1108 |
| - 'etree' are supported. With 'lxml', the ability to use XSLT |
1109 |
| - stylesheet is supported. |
1110 |
| - stylesheet : str, path object or file-like object, optional |
1111 |
| - A URL, file-like object, or a raw string containing an XSLT |
1112 |
| - script used to transform the raw XML output. Script should use |
1113 |
| - layout of elements and attributes from original output. This |
1114 |
| - argument requires ``lxml`` to be installed. Only XSLT 1.0 |
1115 |
| - scripts and not later versions is currently supported. |
1116 |
| - compression : {{'infer', 'gzip', 'bz2', 'zip', 'xz', None}}, default 'infer' |
1117 |
| - For on-the-fly decompression of on-disk data. If 'infer', then use |
1118 |
| - gzip, bz2, zip or xz if path_or_buffer is a string ending in |
1119 |
| - '.gz', '.bz2', '.zip', or 'xz', respectively, and no decompression |
1120 |
| - otherwise. If using 'zip', the ZIP file must contain only one data |
1121 |
| - file to be read in. Set to None for no decompression. |
1122 |
| - {storage_options} |
1123 |
| - """ |
1124 |
| - |
1125 |
| - from pandas.io.formats.xml import ( |
1126 |
| - EtreeXMLFormatter, |
1127 |
| - LxmlXMLFormatter, |
1128 |
| - ) |
1129 |
| - |
1130 |
| - lxml = import_optional_dependency("lxml.etree", errors="ignore") |
1131 |
| - |
1132 |
| - TreeBuilder: Union[Type[EtreeXMLFormatter], Type[LxmlXMLFormatter]] |
1133 |
| - |
1134 |
| - if parser == "lxml": |
1135 |
| - if lxml is not None: |
1136 |
| - TreeBuilder = LxmlXMLFormatter |
1137 |
| - else: |
1138 |
| - raise ImportError( |
1139 |
| - "lxml not found, please install or use the etree parser." |
1140 |
| - ) |
1141 |
| - |
1142 |
| - elif parser == "etree": |
1143 |
| - TreeBuilder = EtreeXMLFormatter |
1144 |
| - |
1145 |
| - else: |
1146 |
| - raise ValueError("Values for parser can only be lxml or etree.") |
1147 |
| - |
1148 |
| - xml_formatter = TreeBuilder( |
1149 |
| - self.fmt, |
1150 |
| - path_or_buffer=path_or_buffer, |
1151 |
| - index=index, |
1152 |
| - root_name=root_name, |
1153 |
| - row_name=row_name, |
1154 |
| - na_rep=na_rep, |
1155 |
| - attr_cols=attr_cols, |
1156 |
| - elem_cols=elem_cols, |
1157 |
| - namespaces=namespaces, |
1158 |
| - prefix=prefix, |
1159 |
| - encoding=encoding, |
1160 |
| - xml_declaration=xml_declaration, |
1161 |
| - pretty_print=pretty_print, |
1162 |
| - stylesheet=stylesheet, |
1163 |
| - compression=compression, |
1164 |
| - storage_options=storage_options, |
1165 |
| - ) |
1166 |
| - |
1167 |
| - return xml_formatter.write_output() |
1168 |
| - |
1169 | 1036 | def to_string(
|
1170 | 1037 | self,
|
1171 | 1038 | buf: Optional[FilePathOrBuffer[str]] = None,
|
|
0 commit comments