Skip to content
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

REF: make selection not a state variable in io.pytables #29804

Merged
merged 1 commit into from
Nov 25, 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
27 changes: 14 additions & 13 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3218,7 +3218,6 @@ def __init__(self, *args, **kwargs):
self.metadata = []
self.info = dict()
self.nan_rep = None
self.selection = None

@property
def table_type_short(self) -> str:
Expand Down Expand Up @@ -3611,8 +3610,8 @@ def read_axes(self, where, **kwargs) -> bool:
return False

# create the selection
self.selection = Selection(self, where=where, **kwargs)
values = self.selection.select()
selection = Selection(self, where=where, **kwargs)
values = selection.select()

# convert the data
for a in self.axes:
Expand Down Expand Up @@ -3902,7 +3901,7 @@ def get_blk_items(mgr, blocks):
if validate:
self.validate(existing_table)

def process_axes(self, obj, columns=None):
def process_axes(self, obj, selection: "Selection", columns=None):
""" process axes filters """

# make a copy to avoid side effects
Expand All @@ -3911,6 +3910,7 @@ def process_axes(self, obj, columns=None):

# make sure to include levels if we have them
if columns is not None and self.is_multi_index:
assert isinstance(self.levels, list) # assured by is_multi_index
for n in self.levels:
if n not in columns:
columns.insert(0, n)
Expand All @@ -3920,8 +3920,8 @@ def process_axes(self, obj, columns=None):
obj = _reindex_axis(obj, axis, labels, columns)

# apply the selection filters (but keep in the same order)
if self.selection.filter is not None:
for field, op, filt in self.selection.filter.format():
if selection.filter is not None:
for field, op, filt in selection.filter.format():

def process_filter(field, filt):

Expand Down Expand Up @@ -4014,10 +4014,10 @@ def read_coordinates(
return False

# create the selection
self.selection = Selection(self, where=where, start=start, stop=stop)
coords = self.selection.select_coords()
if self.selection.filter is not None:
for field, op, filt in self.selection.filter.format():
selection = Selection(self, where=where, start=start, stop=stop)
coords = selection.select_coords()
if selection.filter is not None:
for field, op, filt in selection.filter.format():
data = self.read_column(
field, start=coords.min(), stop=coords.max() + 1
)
Expand Down Expand Up @@ -4302,8 +4302,8 @@ def delete(

# create the selection
table = self.table
self.selection = Selection(self, where, start=start, stop=stop)
values = self.selection.select_coords()
selection = Selection(self, where, start=start, stop=stop)
values = selection.select_coords()

# delete the rows in reverse order
sorted_series = Series(values).sort_values()
Expand Down Expand Up @@ -4406,8 +4406,9 @@ def read(self, where=None, columns=None, **kwargs):
else:
df = concat(frames, axis=1)

selection = Selection(self, where=where, **kwargs)
# apply the selection filters & axis orderings
df = self.process_axes(df, columns=columns)
df = self.process_axes(df, selection=selection, columns=columns)

return df

Expand Down