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

Method read_index_node

pandas/io/pytables.py:3198–3250  ·  view source on GitHub ↗
(
        self, node: Node, start: int | None = None, stop: int | None = None
    )

Source from the content-addressed store, hash-verified

3196 )
3197
3198 def read_index_node(
3199 self, node: Node, start: int | None = None, stop: int | None = None
3200 ) -> Index:
3201 data = node[start:stop]
3202 # If the index was an empty array write_array_empty() will
3203 # have written a sentinel. Here we replace it with the original.
3204 if "shape" in node._v_attrs and np.prod(node._v_attrs.shape) == 0:
3205 data = np.empty(node._v_attrs.shape, dtype=node._v_attrs.value_type)
3206 kind = node._v_attrs.kind
3207 name = None
3208
3209 if "name" in node._v_attrs:
3210 name = _ensure_str(node._v_attrs.name)
3211
3212 attrs = node._v_attrs
3213 factory, kwargs = self._get_index_factory(attrs)
3214
3215 if kind in ("date", "object"):
3216 index = factory(
3217 _unconvert_index(
3218 data, kind, encoding=self.encoding, errors=self.errors
3219 ),
3220 dtype=object,
3221 **kwargs,
3222 )
3223 else:
3224 try:
3225 index = factory(
3226 _unconvert_index(
3227 data, kind, encoding=self.encoding, errors=self.errors
3228 ),
3229 **kwargs,
3230 )
3231 except UnicodeEncodeError as err:
3232 if (
3233 self.errors == "surrogatepass"
3234 and using_string_dtype()
3235 and str(err).endswith("surrogates not allowed")
3236 and HAS_PYARROW
3237 ):
3238 index = factory(
3239 _unconvert_index(
3240 data, kind, encoding=self.encoding, errors=self.errors
3241 ),
3242 dtype=StringDtype(storage="python", na_value=np.nan),
3243 **kwargs,
3244 )
3245 else:
3246 raise
3247
3248 index.name = name
3249
3250 return index
3251
3252 def write_array_empty(self, key: str, value: ArrayLike) -> None:
3253 """write a 0-len array"""

Callers 2

read_indexMethod · 0.95
read_multi_indexMethod · 0.95

Calls 8

_get_index_factoryMethod · 0.95
using_string_dtypeFunction · 0.90
StringDtypeClass · 0.90
_ensure_strFunction · 0.85
_unconvert_indexFunction · 0.85
endswithMethod · 0.80
prodMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected