Skip to content

Commit

Permalink
REF: avoid returning self in io.pytables (#29776)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Nov 22, 2019
1 parent 3adc2e7 commit e8c370a
Showing 1 changed file with 17 additions and 35 deletions.
52 changes: 17 additions & 35 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,18 +1757,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 @@ -1843,8 +1836,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 @@ -1965,8 +1956,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 @@ -2039,14 +2028,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 @@ -2486,8 +2471,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 @@ -3768,9 +3751,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 @@ -3797,10 +3783,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 @@ -4069,19 +4057,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

0 comments on commit e8c370a

Please sign in to comment.