Skip to content

REF: make pytables.IndexCol.itemsize a property #30082

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 1 commit into from
Dec 5, 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
9 changes: 5 additions & 4 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,6 @@ def __init__(
kind=None,
typ=None,
cname: Optional[str] = None,
itemsize=None,
axis=None,
pos=None,
freq=None,
Expand All @@ -1896,7 +1895,6 @@ def __init__(
self.values = values
self.kind = kind
self.typ = typ
self.itemsize = itemsize
self.name = name
self.cname = cname or name
self.axis = axis
Expand All @@ -1916,6 +1914,11 @@ def __init__(
assert isinstance(self.name, str)
assert isinstance(self.cname, str)

@property
def itemsize(self) -> int:
# Assumes self.typ has already been initialized
return self.typ.itemsize

@property
def kind_attr(self) -> str:
return f"{self.name}_kind"
Expand Down Expand Up @@ -2338,7 +2341,6 @@ def get_atom_string(self, shape, itemsize):
return _tables().StringCol(itemsize=itemsize, shape=shape[0])

def set_atom_string(self, itemsize: int, data_converted: np.ndarray):
self.itemsize = itemsize
self.kind = "string"
self.typ = self.get_atom_string(data_converted.shape, itemsize)
self.set_data(data_converted.astype(f"|S{itemsize}", copy=False))
Expand Down Expand Up @@ -4724,7 +4726,6 @@ def _convert_index(name: str, index: Index, encoding=None, errors="strict"):
converted,
"string",
_tables().StringCol(itemsize),
itemsize=itemsize,
index_name=index_name,
)

Expand Down