Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_parameters(self, size, start, step):
"""Checks if parameters are data slice offsets."""
if not isinstance(size, DataSliceStep):
size = DataSliceStep(size)
start = start or self._df.index[0]
if not isinstance(start, DataSliceOffset):
start = DataSliceOffset(start)
step = step or size
if not isinstance(step, DataSliceStep):
step = DataSliceStep(step)
info = 'offset must be positive'
assert size._is_positive, info
assert step._is_positive, info
if any(offset._is_offset_period for offset in (size, start, step)):
info = 'offset by time requires a time index'
assert self._is_time_index, info
return size, start, step
def _check_parameters(self, size, start, step):
"""Checks if parameters are data slice offsets."""
if not isinstance(size, DataSliceStep):
size = DataSliceStep(size)
start = start or self._df.index[0]
if not isinstance(start, DataSliceOffset):
start = DataSliceOffset(start)
step = step or size
if not isinstance(step, DataSliceStep):
step = DataSliceStep(step)
info = 'offset must be positive'
assert size._is_positive, info
assert step._is_positive, info
if any(offset._is_offset_period for offset in (size, start, step)):
info = 'offset by time requires a time index'
assert self._is_time_index, info
return size, start, step
for parser in self._parsers:
try:
value = parser(self.value)
if value is not None:
self.value = value
break
except Exception:
continue
@property
def _parsers(self):
"""Returns the value parsers."""
return pd.Timestamp, self._parse_offset_alias, pd.Timedelta
class DataSliceStep(DataSliceOffset):
@property
def _is_valid_offset(self):
"""Whether offset is a valid type."""
value = self._is_offset_position
value |= self._is_offset_period
return value
@property
def _parsers(self):
"""Returns the value parsers."""
return self._parse_offset_alias, pd.Timedelta