REF: make selection not a state variable in io.pytables (#29804) · pandas-dev/pandas@8602c23 (original) (raw)
`@@ -3185,7 +3185,6 @@ def init(self, *args, **kwargs):
`
3185
3185
`self.metadata = []
`
3186
3186
`self.info = dict()
`
3187
3187
`self.nan_rep = None
`
3188
``
`-
self.selection = None
`
3189
3188
``
3190
3189
`@property
`
3191
3190
`def table_type_short(self) -> str:
`
`@@ -3568,8 +3567,8 @@ def read_axes(self, where, **kwargs) -> bool:
`
3568
3567
`return False
`
3569
3568
``
3570
3569
`# create the selection
`
3571
``
`-
self.selection = Selection(self, where=where, **kwargs)
`
3572
``
`-
values = self.selection.select()
`
``
3570
`+
selection = Selection(self, where=where, **kwargs)
`
``
3571
`+
values = selection.select()
`
3573
3572
``
3574
3573
`# convert the data
`
3575
3574
`for a in self.axes:
`
`@@ -3857,7 +3856,7 @@ def get_blk_items(mgr, blocks):
`
3857
3856
`if validate:
`
3858
3857
`self.validate(existing_table)
`
3859
3858
``
3860
``
`-
def process_axes(self, obj, columns=None):
`
``
3859
`+
def process_axes(self, obj, selection: "Selection", columns=None):
`
3861
3860
`""" process axes filters """
`
3862
3861
``
3863
3862
`# make a copy to avoid side effects
`
`@@ -3866,6 +3865,7 @@ def process_axes(self, obj, columns=None):
`
3866
3865
``
3867
3866
`# make sure to include levels if we have them
`
3868
3867
`if columns is not None and self.is_multi_index:
`
``
3868
`+
assert isinstance(self.levels, list) # assured by is_multi_index
`
3869
3869
`for n in self.levels:
`
3870
3870
`if n not in columns:
`
3871
3871
`columns.insert(0, n)
`
`@@ -3875,8 +3875,8 @@ def process_axes(self, obj, columns=None):
`
3875
3875
`obj = _reindex_axis(obj, axis, labels, columns)
`
3876
3876
``
3877
3877
`# apply the selection filters (but keep in the same order)
`
3878
``
`-
if self.selection.filter is not None:
`
3879
``
`-
for field, op, filt in self.selection.filter.format():
`
``
3878
`+
if selection.filter is not None:
`
``
3879
`+
for field, op, filt in selection.filter.format():
`
3880
3880
``
3881
3881
`def process_filter(field, filt):
`
3882
3882
``
`@@ -3966,10 +3966,10 @@ def read_coordinates(
`
3966
3966
`return False
`
3967
3967
``
3968
3968
`# create the selection
`
3969
``
`-
self.selection = Selection(self, where=where, start=start, stop=stop)
`
3970
``
`-
coords = self.selection.select_coords()
`
3971
``
`-
if self.selection.filter is not None:
`
3972
``
`-
for field, op, filt in self.selection.filter.format():
`
``
3969
`+
selection = Selection(self, where=where, start=start, stop=stop)
`
``
3970
`+
coords = selection.select_coords()
`
``
3971
`+
if selection.filter is not None:
`
``
3972
`+
for field, op, filt in selection.filter.format():
`
3973
3973
`data = self.read_column(
`
3974
3974
`field, start=coords.min(), stop=coords.max() + 1
`
3975
3975
` )
`
`@@ -4245,8 +4245,8 @@ def delete(
`
4245
4245
``
4246
4246
`# create the selection
`
4247
4247
`table = self.table
`
4248
``
`-
self.selection = Selection(self, where, start=start, stop=stop)
`
4249
``
`-
values = self.selection.select_coords()
`
``
4248
`+
selection = Selection(self, where, start=start, stop=stop)
`
``
4249
`+
values = selection.select_coords()
`
4250
4250
``
4251
4251
`# delete the rows in reverse order
`
4252
4252
`sorted_series = Series(values).sort_values()
`
`@@ -4349,8 +4349,9 @@ def read(self, where=None, columns=None, **kwargs):
`
4349
4349
`else:
`
4350
4350
`df = concat(frames, axis=1)
`
4351
4351
``
``
4352
`+
selection = Selection(self, where=where, **kwargs)
`
4352
4353
`# apply the selection filters & axis orderings
`
4353
``
`-
df = self.process_axes(df, columns=columns)
`
``
4354
`+
df = self.process_axes(df, selection=selection, columns=columns)
`
4354
4355
``
4355
4356
`return df
`
4356
4357
``