MCPcopy
hub / github.com/pandas-dev/pandas / _build_tree

Method _build_tree

pandas/io/formats/xml.py:455–492  ·  view source on GitHub ↗

Build tree from data. This method initializes the root and builds attributes and elements with optional namespaces.

(self)

Source from the content-addressed store, hash-verified

453 self._convert_empty_str_key()
454
455 def _build_tree(self) -> bytes:
456 """
457 Build tree from data.
458
459 This method initializes the root and builds attributes and elements
460 with optional namespaces.
461 """
462 from lxml.etree import (
463 Element,
464 SubElement,
465 tostring,
466 )
467
468 self.root = Element(f"{self.prefix_uri}{self.root_name}", nsmap=self.namespaces)
469
470 for d in self.frame_dicts.values():
471 elem_row = SubElement(self.root, f"{self.prefix_uri}{self.row_name}")
472
473 if not self.attr_cols and not self.elem_cols:
474 self.elem_cols = list(d.keys())
475 self._build_elems(d, elem_row)
476
477 else:
478 elem_row = self._build_attribs(d, elem_row)
479 self._build_elems(d, elem_row)
480
481 self.out_xml = tostring(
482 self.root,
483 pretty_print=self.pretty_print,
484 method="xml",
485 encoding=self.encoding,
486 xml_declaration=self.xml_declaration,
487 )
488
489 if self.stylesheet is not None:
490 self.out_xml = self._transform_doc()
491
492 return self.out_xml
493
494 def _convert_empty_str_key(self) -> None:
495 """

Callers

nothing calls this directly

Calls 5

_transform_docMethod · 0.95
_build_elemsMethod · 0.80
_build_attribsMethod · 0.80
valuesMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected