Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _slice_by_column(self, df):
"""Slices the data frame by an existing column."""
slices = df.groupby(self.window_size, sort=False)
slice_number = 1
for group, ds in slices:
ds = DataSliceFrame(ds)
ds.context = DataSliceContext(
slice_number=slice_number,
slice_start=ds.first_valid_index(),
slice_stop=ds.last_valid_index(),
)
setattr(ds.context, self.window_size, group)
del ds.context.next_start
slice_number += 1
yield ds
def _constructor(self):
return DataSliceFrame
start (int or str): Where to start the first data slice.
step (int or str): The step size between data slices. Default value is the data slice size.
drop_empty (bool): Whether to drop empty data slices. Default value is True.
Returns:
ds (generator): Returns a generator of data slices.
"""
self._check_index()
size, start, step = self._check_parameters(size, start, step)
df = self._apply_start(self._df, start)
if df.empty: return
if step._is_offset_position:
start.value = df.index[0]
df = DataSliceFrame(df)
slice_number, stop_value = 1, df.index[-1]
while not df.empty and start.value <= stop_value:
ds = self._apply_size(df, start, size)
df = self._apply_step(df, start, step)
ds.context.next_start = start.value
if ds.empty and drop_empty: continue
ds.context.slice_number = slice_number
slice_number += 1
yield ds