diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index b40637b978988..fe34f009165ac 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2111,10 +2111,6 @@ def set_info(self, info): if idx is not None: self.__dict__.update(idx) - def get_attr(self): - """ set the kind for this column """ - self.kind = getattr(self.attrs, self.kind_attr, None) - def set_attr(self): """ set the kind for this column """ setattr(self.attrs, self.kind_attr, self.kind) @@ -2161,9 +2157,6 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str): assert isinstance(values, np.ndarray), type(values) self.values = Int64Index(np.arange(len(values))) - def get_attr(self): - pass - def set_attr(self): pass @@ -2363,6 +2356,7 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str): self.data = values own_data = self.data + assert isinstance(own_data, np.ndarray) # for mypy # use the meta if needed meta = _ensure_decoded(self.meta) @@ -2430,15 +2424,6 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str): self.data = own_data - def get_attr(self): - """ get the data for this column """ - self.values = getattr(self.attrs, self.kind_attr, None) - self.dtype = getattr(self.attrs, self.dtype_attr, None) - self.meta = getattr(self.attrs, self.meta_attr, None) - assert self.typ is not None - assert self.dtype is not None - self.kind = _dtype_to_kind(self.dtype) - def set_attr(self): """ set the data for this column """ setattr(self.attrs, self.kind_attr, self.values) @@ -2477,8 +2462,7 @@ def get_atom_timedelta64(cls, shape): class GenericDataIndexableCol(DataIndexableCol): """ represent a generic pytables data column """ - def get_attr(self): - pass + pass class Fixed: @@ -3424,6 +3408,7 @@ def indexables(self): _indexables = [] desc = self.description + table_attrs = self.table.attrs # Note: each of the `name` kwargs below are str, ensured # by the definition in index_cols. @@ -3432,16 +3417,20 @@ def indexables(self): atom = getattr(desc, name) md = self.read_metadata(name) meta = "category" if md is not None else None + + kind_attr = f"{name}_kind" + kind = getattr(table_attrs, kind_attr, None) + index_col = IndexCol( name=name, axis=axis, pos=i, + kind=kind, typ=atom, table=self.table, meta=meta, metadata=md, ) - index_col.get_attr() _indexables.append(index_col) # values columns @@ -3456,18 +3445,29 @@ def f(i, c): atom = getattr(desc, c) adj_name = _maybe_adjust_name(c, self.version) + + # TODO: why kind_attr here? + values = getattr(table_attrs, f"{adj_name}_kind", None) + dtype = getattr(table_attrs, f"{adj_name}_dtype", None) + kind = _dtype_to_kind(dtype) + md = self.read_metadata(c) - meta = "category" if md is not None else None + # TODO: figure out why these two versions of `meta` dont always match. + # meta = "category" if md is not None else None + meta = getattr(table_attrs, f"{adj_name}_meta", None) + obj = klass( name=adj_name, cname=c, + values=values, + kind=kind, pos=base_pos + i, typ=atom, table=self.table, meta=meta, metadata=md, + dtype=dtype, ) - obj.get_attr() return obj # Note: the definition of `values_cols` ensures that each @@ -4491,7 +4491,6 @@ def indexables(self): index_col = GenericIndexCol( name="index", axis=0, table=self.table, meta=meta, metadata=md ) - index_col.get_attr() _indexables = [index_col] @@ -4510,7 +4509,6 @@ def indexables(self): meta=meta, metadata=md, ) - dc.get_attr() _indexables.append(dc) return _indexables