Skip to content

REF: finish setting pytables IndexCol attrs in constructor #30161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2477,8 +2462,7 @@ def get_atom_timedelta64(cls, shape):
class GenericDataIndexableCol(DataIndexableCol):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just blow this class away altogether now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth a shot

""" represent a generic pytables data column """

def get_attr(self):
pass
pass


class Fixed:
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is going on here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ever place where we set self.meta it is equivalent to meta = "category" if md is not None else none, but in this one place where we read it from the file, there is one test case where it doesnt match, and i dont know why.

if/when that is resolved, meta can be made a property

# 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
Expand Down Expand Up @@ -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]

Expand All @@ -4510,7 +4509,6 @@ def indexables(self):
meta=meta,
metadata=md,
)
dc.get_attr()
_indexables.append(dc)

return _indexables
Expand Down