Skip to content

REF: avoid returning self in io.pytables #29776

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
Nov 22, 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
52 changes: 17 additions & 35 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,18 +1760,11 @@ def __init__(
assert isinstance(self.cname, str)
assert isinstance(self.kind_attr, str)

def set_axis(self, axis: int):
""" set the axis over which I index """
self.axis = axis

return self

def set_pos(self, pos: int):
""" set the position of this column in the Table """
self.pos = pos
if pos is not None and self.typ is not None:
self.typ._v_pos = pos
return self

def __repr__(self) -> str:
temp = tuple(
Expand Down Expand Up @@ -1846,8 +1839,6 @@ def convert(

self.values = _set_tz(self.values, self.tz)

return self

def take_data(self):
""" return the values & release the memory """
self.values, values = None, self.values
Expand Down Expand Up @@ -1968,8 +1959,6 @@ def update_info(self, info):
if value is not None or existing_value is not None:
idx[key] = value

return self

def set_info(self, info):
""" set my state from the passed info """
idx = info.get(self.name)
Expand Down Expand Up @@ -2042,14 +2031,10 @@ def convert(
"""
assert self.table is not None # for mypy

assert self.table is not None

_start = start if start is not None else 0
_stop = min(stop, self.table.nrows) if stop is not None else self.table.nrows
self.values = Int64Index(np.arange(_stop - _start))

return self

def get_attr(self):
pass

Expand Down Expand Up @@ -2489,8 +2474,6 @@ def convert(self, values, nan_rep, encoding, errors, start=None, stop=None):
self.data, nan_rep=nan_rep, encoding=encoding, errors=errors
)

return self

def get_attr(self):
""" get the data for this column """
self.values = getattr(self.attrs, self.kind_attr, None)
Expand Down Expand Up @@ -3800,9 +3783,12 @@ def create_axes(

if i in axes:
name = obj._AXIS_NAMES[i]
index_axes_map[i] = _convert_index(
new_index = _convert_index(
name, a, self.encoding, self.errors, self.format_type
).set_axis(i)
)
new_index.axis = i
index_axes_map[i] = new_index

else:

# we might be able to change the axes on the appending data if
Expand All @@ -3829,10 +3815,12 @@ def create_axes(
self.non_index_axes.append((i, append_axis))

# set axis positions (based on the axes)
self.index_axes = [
index_axes_map[a].set_pos(j).update_info(self.info)
for j, a in enumerate(axes)
]
new_index_axes = [index_axes_map[a] for a in axes]
for j, iax in enumerate(new_index_axes):
iax.set_pos(j)
iax.update_info(self.info)
self.index_axes = new_index_axes

j = len(self.index_axes)

# check for column conflicts
Expand Down Expand Up @@ -4101,19 +4089,13 @@ def read_column(
# column must be an indexable or a data column
c = getattr(self.table.cols, column)
a.set_info(self.info)
return Series(
_set_tz(
a.convert(
c[start:stop],
nan_rep=self.nan_rep,
encoding=self.encoding,
errors=self.errors,
).take_data(),
a.tz,
True,
),
name=column,
a.convert(
c[start:stop],
nan_rep=self.nan_rep,
encoding=self.encoding,
errors=self.errors,
)
return Series(_set_tz(a.take_data(), a.tz, True), name=column)

raise KeyError("column [{column}] not found in the table".format(column=column))

Expand Down