MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / dataframe_to_xml

Function dataframe_to_xml

_pydevd_bundle/pydevd_vars.py:783–861  ·  view source on GitHub ↗

:type df: pandas.core.frame.DataFrame :type name: str :type coffset: int :type roffset: int :type rows: int :type cols: int :type format: str

(df, name, roffset, coffset, rows, cols, format)

Source from the content-addressed store, hash-verified

781
782
783def dataframe_to_xml(df, name, roffset, coffset, rows, cols, format):
784 """
785 :type df: pandas.core.frame.DataFrame
786 :type name: str
787 :type coffset: int
788 :type roffset: int
789 :type rows: int
790 :type cols: int
791 :type format: str
792
793
794 """
795 num_rows = min(df.shape[0], MAX_SLICE_SIZE)
796 num_cols = min(df.shape[1], MAX_SLICE_SIZE)
797 if (num_rows, num_cols) != df.shape:
798 df = df.iloc[0:num_rows, 0:num_cols]
799 slice = ".iloc[0:%s, 0:%s]" % (num_rows, num_cols)
800 else:
801 slice = ""
802 slice = name + slice
803 xml = '<array slice="%s" rows="%s" cols="%s" format="" type="" max="0" min="0"/>\n' % (slice, num_rows, num_cols)
804
805 if (rows, cols) == (-1, -1):
806 rows, cols = num_rows, num_cols
807
808 rows = min(rows, MAXIMUM_ARRAY_SIZE)
809 cols = min(min(cols, MAXIMUM_ARRAY_SIZE), num_cols)
810 # need to precompute column bounds here before slicing!
811 col_bounds = [None] * cols
812 for col in range(cols):
813 dtype = df.dtypes.iloc[coffset + col].kind
814 if dtype in "biufc":
815 cvalues = df.iloc[:, coffset + col]
816 bounds = (cvalues.min(), cvalues.max())
817 else:
818 bounds = (0, 0)
819 col_bounds[col] = bounds
820
821 df = df.iloc[roffset : roffset + rows, coffset : coffset + cols]
822 rows, cols = df.shape
823
824 xml += '<headerdata rows="%s" cols="%s">\n' % (rows, cols)
825 format = format.replace("%", "")
826 col_formats = []
827
828 get_label = lambda label: str(label) if not isinstance(label, tuple) else "/".join(map(str, label))
829
830 for col in range(cols):
831 dtype = df.dtypes.iloc[col].kind
832 if dtype == "f" and format:
833 fmt = format
834 elif dtype == "f":
835 fmt = ".5f"
836 elif dtype == "i" or dtype == "u":
837 fmt = "d"
838 else:
839 fmt = "s"
840 col_formats.append("%" + fmt)

Callers 1

table_like_struct_to_xmlFunction · 0.85

Calls 3

var_to_xmlFunction · 0.90
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected