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

Method _create_storer

pandas/io/pytables.py:1823–1912  ·  view source on GitHub ↗

return a suitable class to operate

(
        self,
        group,
        format=None,
        value: DataFrame | Series | None = None,
        encoding: str = "UTF-8",
        errors: str = "strict",
    )

Source from the content-addressed store, hash-verified

1821 return format
1822
1823 def _create_storer(
1824 self,
1825 group,
1826 format=None,
1827 value: DataFrame | Series | None = None,
1828 encoding: str = "UTF-8",
1829 errors: str = "strict",
1830 ) -> GenericFixed | Table:
1831 """return a suitable class to operate"""
1832 cls: type[GenericFixed | Table]
1833
1834 if value is not None and not isinstance(value, (Series, DataFrame)):
1835 raise TypeError("value must be None, Series, or DataFrame")
1836
1837 pt = getattr(group._v_attrs, "pandas_type", None)
1838 tt = getattr(group._v_attrs, "table_type", None)
1839
1840 # infer the pt from the passed value
1841 if pt is None:
1842 if value is None:
1843 _tables()
1844 assert _table_mod is not None # for mypy
1845 if getattr(group, "table", None) or isinstance(
1846 group, _table_mod.table.Table
1847 ):
1848 pt = "frame_table"
1849 tt = "generic_table"
1850 else:
1851 raise TypeError(
1852 "cannot create a storer if the object is not existing "
1853 "nor a value are passed"
1854 )
1855 else:
1856 if isinstance(value, Series):
1857 pt = "series"
1858 else:
1859 pt = "frame"
1860
1861 # we are actually a table
1862 if format == "table":
1863 pt += "_table"
1864
1865 # a storer node
1866 if "table" not in pt:
1867 _STORER_MAP = {"series": SeriesFixed, "frame": FrameFixed}
1868 try:
1869 cls = _STORER_MAP[pt]
1870 except KeyError as err:
1871 raise TypeError(
1872 f"cannot properly create the storer for: [_STORER_MAP] [group->"
1873 f"{group},value->{type(value)},format->{format}"
1874 ) from err
1875 return cls(self, group, encoding=encoding, errors=errors)
1876
1877 # existing node (and must be a table)
1878 if tt is None:
1879 # if we are a writer, determine the tt
1880 if value is not None:

Callers 4

selectMethod · 0.95
get_storerMethod · 0.95
_write_to_groupMethod · 0.95
_read_groupMethod · 0.95

Calls 2

_tablesFunction · 0.85
clsFunction · 0.85

Tested by

no test coverage detected