mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-05 05:20:30 +08:00
MAINT: Remove outdated compat code.
This commit is contained in:
@@ -80,12 +80,6 @@ from zipline.testing.fixtures import (
|
||||
)
|
||||
from zipline.utils.memoize import lazyval
|
||||
from zipline.utils.numpy_utils import bool_dtype, datetime64ns_dtype
|
||||
from zipline.utils.pandas_utils import (
|
||||
ewma,
|
||||
ewmstd,
|
||||
rolling_apply,
|
||||
rolling_mean,
|
||||
)
|
||||
|
||||
|
||||
class RollingSumDifference(CustomFactor):
|
||||
@@ -1010,16 +1004,16 @@ class SyntheticBcolzTestCase(WithAdjustmentReader,
|
||||
# Shift back the raw inputs by a trading day because we expect our
|
||||
# computed results to be computed using values anchored on the
|
||||
# **previous** day's data.
|
||||
expected_raw = rolling_mean(
|
||||
DataFrame(
|
||||
expected_bar_values_2d(
|
||||
dates - self.trading_calendar.day,
|
||||
self.equity_info,
|
||||
'close',
|
||||
),
|
||||
expected_raw = DataFrame(
|
||||
expected_bar_values_2d(
|
||||
dates - self.trading_calendar.day,
|
||||
self.equity_info,
|
||||
'close',
|
||||
),
|
||||
).rolling(
|
||||
window_length,
|
||||
min_periods=1,
|
||||
).mean(
|
||||
).values
|
||||
|
||||
expected = DataFrame(
|
||||
@@ -1131,10 +1125,11 @@ class ParameterizedFactorTestCase(WithTradingEnvironment, ZiplineTestCase):
|
||||
# Don't use it outside of testing. We're using rolling-apply of an
|
||||
# ewma (which is itself a rolling-window function) because we only want
|
||||
# to look at ``window_length`` rows at a time.
|
||||
return rolling_apply(
|
||||
self.raw_data,
|
||||
window_length,
|
||||
lambda window: ewma(DataFrame(window), span=span).values[-1],
|
||||
return self.raw_data.rolling(window_length).apply(
|
||||
lambda subarray: (DataFrame(subarray)
|
||||
.ewm(span=span)
|
||||
.mean()
|
||||
.values[-1])
|
||||
)[window_length:]
|
||||
|
||||
def expected_ewmstd(self, window_length, decay_rate):
|
||||
@@ -1145,10 +1140,11 @@ class ParameterizedFactorTestCase(WithTradingEnvironment, ZiplineTestCase):
|
||||
# EWMSTD. Don't use it outside of testing. We're using rolling-apply
|
||||
# of an ewma (which is itself a rolling-window function) because we
|
||||
# only want to look at ``window_length`` rows at a time.
|
||||
return rolling_apply(
|
||||
self.raw_data,
|
||||
window_length,
|
||||
lambda window: ewmstd(DataFrame(window), span=span).values[-1],
|
||||
return self.raw_data.rolling(window_length).apply(
|
||||
lambda subarray: (DataFrame(subarray)
|
||||
.ewm(span=span)
|
||||
.std()
|
||||
.values[-1])
|
||||
)[window_length:]
|
||||
|
||||
@parameterized.expand([
|
||||
@@ -1273,7 +1269,7 @@ class ParameterizedFactorTestCase(WithTradingEnvironment, ZiplineTestCase):
|
||||
expected_1 = (self.raw_data[5:] ** 2) * 2
|
||||
assert_frame_equal(results['dv1'].unstack(), expected_1)
|
||||
|
||||
expected_5 = rolling_mean((self.raw_data ** 2) * 2, window=5)[5:]
|
||||
expected_5 = ((self.raw_data ** 2) * 2).rolling(5).mean()[5:]
|
||||
assert_frame_equal(results['dv5'].unstack(), expected_5)
|
||||
|
||||
# The following two use USEquityPricing.open and .volume as inputs.
|
||||
@@ -1283,9 +1279,11 @@ class ParameterizedFactorTestCase(WithTradingEnvironment, ZiplineTestCase):
|
||||
* self.raw_data[5:] * 2).fillna(0)
|
||||
assert_frame_equal(results['dv1_nan'].unstack(), expected_1_nan)
|
||||
|
||||
expected_5_nan = rolling_mean((self.raw_data_with_nans
|
||||
* self.raw_data * 2).fillna(0),
|
||||
window=5)[5:]
|
||||
expected_5_nan = ((self.raw_data_with_nans * self.raw_data * 2)
|
||||
.fillna(0)
|
||||
.rolling(5).mean()
|
||||
[5:])
|
||||
|
||||
assert_frame_equal(results['dv5_nan'].unstack(), expected_5_nan)
|
||||
|
||||
|
||||
|
||||
@@ -187,7 +187,6 @@ from zipline.utils.input_validation import (
|
||||
optionally,
|
||||
)
|
||||
from zipline.utils.numpy_utils import bool_dtype, categorical_dtype
|
||||
from zipline.utils.pandas_utils import sort_values
|
||||
from zipline.utils.pool import SequentialPool
|
||||
from zipline.utils.preprocess import preprocess
|
||||
|
||||
@@ -754,7 +753,7 @@ def overwrite_novel_deltas(baseline, deltas, dates):
|
||||
ignore_index=True,
|
||||
copy=False,
|
||||
)
|
||||
sort_values(cat, TS_FIELD_NAME, inplace=True)
|
||||
cat.sort_values(TS_FIELD_NAME, inplace=True)
|
||||
return cat, non_novel_deltas
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ from pandas import (
|
||||
from zipline.lib.adjusted_array import AdjustedArray
|
||||
from zipline.lib.adjustment import make_adjustment_from_labels
|
||||
from zipline.utils.numpy_utils import as_column
|
||||
from zipline.utils.pandas_utils import sort_values
|
||||
from .base import PipelineLoader
|
||||
|
||||
ADJUSTMENT_COLUMNS = Index([
|
||||
@@ -73,7 +72,7 @@ class DataFrameLoader(PipelineLoader):
|
||||
else:
|
||||
# Ensure that columns are in the correct order.
|
||||
adjustments = adjustments.reindex_axis(ADJUSTMENT_COLUMNS, axis=1)
|
||||
sort_values(adjustments, ['apply_date', 'sid'], inplace=True)
|
||||
adjustments.sort_values(['apply_date', 'sid'], inplace=True)
|
||||
|
||||
self.adjustments = adjustments
|
||||
self.adjustment_apply_dates = DatetimeIndex(adjustments.apply_date)
|
||||
|
||||
@@ -12,6 +12,10 @@ from distutils.version import StrictVersion
|
||||
pandas_version = StrictVersion(pd.__version__)
|
||||
|
||||
|
||||
def july_5th_holiday_observance(datetime_index):
|
||||
return datetime_index[datetime_index.year != 2013]
|
||||
|
||||
|
||||
def explode(df):
|
||||
"""
|
||||
Take a DataFrame and return a triple of
|
||||
@@ -21,19 +25,6 @@ def explode(df):
|
||||
return df.index, df.columns, df.values
|
||||
|
||||
|
||||
try:
|
||||
# This branch is hit in pandas 17
|
||||
sort_values = pd.DataFrame.sort_values
|
||||
except AttributeError:
|
||||
# This branch is hit in pandas 16
|
||||
sort_values = pd.DataFrame.sort
|
||||
|
||||
if pandas_version >= StrictVersion('0.17.1'):
|
||||
july_5th_holiday_observance = lambda dtix: dtix[dtix.year != 2013]
|
||||
else:
|
||||
july_5th_holiday_observance = lambda dt: None if dt.year == 2013 else dt
|
||||
|
||||
|
||||
def _time_to_micros(time):
|
||||
"""Convert a time into microseconds since midnight.
|
||||
Parameters
|
||||
@@ -175,85 +166,3 @@ def ignore_pandas_nan_categorical_warning():
|
||||
category=FutureWarning,
|
||||
)
|
||||
yield
|
||||
|
||||
|
||||
# Remove when we drop support for 0.17
|
||||
if pandas_version >= StrictVersion('0.18'):
|
||||
def rolling_mean(arg,
|
||||
window,
|
||||
min_periods=None,
|
||||
freq=None,
|
||||
center=False,
|
||||
**kwargs):
|
||||
return arg.rolling(
|
||||
window,
|
||||
min_periods=min_periods,
|
||||
freq=freq,
|
||||
center=center,
|
||||
**kwargs
|
||||
).mean()
|
||||
|
||||
def rolling_apply(arg,
|
||||
window,
|
||||
func,
|
||||
min_periods=None,
|
||||
freq=None,
|
||||
center=False,
|
||||
**kwargs):
|
||||
return arg.rolling(
|
||||
window,
|
||||
min_periods=min_periods,
|
||||
freq=freq,
|
||||
center=center,
|
||||
**kwargs
|
||||
).apply(func)
|
||||
|
||||
def ewma(arg,
|
||||
com=None,
|
||||
span=None,
|
||||
halflife=None,
|
||||
alpha=None,
|
||||
min_periods=0,
|
||||
freq=None,
|
||||
adjust=True,
|
||||
how=None,
|
||||
ignore_na=False):
|
||||
|
||||
return arg.ewm(
|
||||
com=com,
|
||||
span=span,
|
||||
halflife=halflife,
|
||||
alpha=alpha,
|
||||
min_periods=min_periods,
|
||||
freq=freq,
|
||||
adjust=adjust,
|
||||
ignore_na=ignore_na,
|
||||
).mean()
|
||||
|
||||
def ewmstd(arg,
|
||||
com=None,
|
||||
span=None,
|
||||
halflife=None,
|
||||
alpha=None,
|
||||
min_periods=0,
|
||||
freq=None,
|
||||
adjust=True,
|
||||
how=None,
|
||||
ignore_na=False):
|
||||
|
||||
return arg.ewm(
|
||||
com=com,
|
||||
span=span,
|
||||
halflife=halflife,
|
||||
alpha=alpha,
|
||||
min_periods=min_periods,
|
||||
freq=freq,
|
||||
adjust=adjust,
|
||||
ignore_na=ignore_na,
|
||||
).std()
|
||||
|
||||
else:
|
||||
rolling_mean = pd.rolling_mean
|
||||
rolling_apply = pd.rolling_apply
|
||||
ewma = pd.ewma
|
||||
ewmstd = pd.ewmstd
|
||||
|
||||
Reference in New Issue
Block a user