Skip to content

Commit e8c370a

Browse files
jbrockmendeljreback
authored andcommitted
REF: avoid returning self in io.pytables (#29776)
1 parent 3adc2e7 commit e8c370a

File tree

1 file changed

+17
-35
lines changed

1 file changed

+17
-35
lines changed

pandas/io/pytables.py

+17-35
Original file line numberDiff line numberDiff line change
@@ -1757,18 +1757,11 @@ def __init__(
17571757
assert isinstance(self.cname, str)
17581758
assert isinstance(self.kind_attr, str)
17591759

1760-
def set_axis(self, axis: int):
1761-
""" set the axis over which I index """
1762-
self.axis = axis
1763-
1764-
return self
1765-
17661760
def set_pos(self, pos: int):
17671761
""" set the position of this column in the Table """
17681762
self.pos = pos
17691763
if pos is not None and self.typ is not None:
17701764
self.typ._v_pos = pos
1771-
return self
17721765

17731766
def __repr__(self) -> str:
17741767
temp = tuple(
@@ -1843,8 +1836,6 @@ def convert(
18431836

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

1846-
return self
1847-
18481839
def take_data(self):
18491840
""" return the values & release the memory """
18501841
self.values, values = None, self.values
@@ -1965,8 +1956,6 @@ def update_info(self, info):
19651956
if value is not None or existing_value is not None:
19661957
idx[key] = value
19671958

1968-
return self
1969-
19701959
def set_info(self, info):
19711960
""" set my state from the passed info """
19721961
idx = info.get(self.name)
@@ -2039,14 +2028,10 @@ def convert(
20392028
"""
20402029
assert self.table is not None # for mypy
20412030

2042-
assert self.table is not None
2043-
20442031
_start = start if start is not None else 0
20452032
_stop = min(stop, self.table.nrows) if stop is not None else self.table.nrows
20462033
self.values = Int64Index(np.arange(_stop - _start))
20472034

2048-
return self
2049-
20502035
def get_attr(self):
20512036
pass
20522037

@@ -2486,8 +2471,6 @@ def convert(self, values, nan_rep, encoding, errors, start=None, stop=None):
24862471
self.data, nan_rep=nan_rep, encoding=encoding, errors=errors
24872472
)
24882473

2489-
return self
2490-
24912474
def get_attr(self):
24922475
""" get the data for this column """
24932476
self.values = getattr(self.attrs, self.kind_attr, None)
@@ -3768,9 +3751,12 @@ def create_axes(
37683751

37693752
if i in axes:
37703753
name = obj._AXIS_NAMES[i]
3771-
index_axes_map[i] = _convert_index(
3754+
new_index = _convert_index(
37723755
name, a, self.encoding, self.errors, self.format_type
3773-
).set_axis(i)
3756+
)
3757+
new_index.axis = i
3758+
index_axes_map[i] = new_index
3759+
37743760
else:
37753761

37763762
# we might be able to change the axes on the appending data if
@@ -3797,10 +3783,12 @@ def create_axes(
37973783
self.non_index_axes.append((i, append_axis))
37983784

37993785
# set axis positions (based on the axes)
3800-
self.index_axes = [
3801-
index_axes_map[a].set_pos(j).update_info(self.info)
3802-
for j, a in enumerate(axes)
3803-
]
3786+
new_index_axes = [index_axes_map[a] for a in axes]
3787+
for j, iax in enumerate(new_index_axes):
3788+
iax.set_pos(j)
3789+
iax.update_info(self.info)
3790+
self.index_axes = new_index_axes
3791+
38043792
j = len(self.index_axes)
38053793

38063794
# check for column conflicts
@@ -4069,19 +4057,13 @@ def read_column(
40694057
# column must be an indexable or a data column
40704058
c = getattr(self.table.cols, column)
40714059
a.set_info(self.info)
4072-
return Series(
4073-
_set_tz(
4074-
a.convert(
4075-
c[start:stop],
4076-
nan_rep=self.nan_rep,
4077-
encoding=self.encoding,
4078-
errors=self.errors,
4079-
).take_data(),
4080-
a.tz,
4081-
True,
4082-
),
4083-
name=column,
4060+
a.convert(
4061+
c[start:stop],
4062+
nan_rep=self.nan_rep,
4063+
encoding=self.encoding,
4064+
errors=self.errors,
40844065
)
4066+
return Series(_set_tz(a.take_data(), a.tz, True), name=column)
40854067

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

0 commit comments

Comments
 (0)