mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-12 11:50:11 +08:00
BUG: DataPanelSource was looping in the incorrect order.
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import pytz
|
import pytz
|
||||||
|
from itertools import cycle
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
@@ -59,16 +60,16 @@ class TestDataFrameSource(TestCase):
|
|||||||
start = pd.datetime(1993, 1, 1, 0, 0, 0, 0, pytz.utc)
|
start = pd.datetime(1993, 1, 1, 0, 0, 0, 0, pytz.utc)
|
||||||
end = pd.datetime(2002, 1, 1, 0, 0, 0, 0, pytz.utc)
|
end = pd.datetime(2002, 1, 1, 0, 0, 0, 0, pytz.utc)
|
||||||
data = factory.load_bars_from_yahoo(stocks=stocks,
|
data = factory.load_bars_from_yahoo(stocks=stocks,
|
||||||
|
indexes={},
|
||||||
start=start,
|
start=start,
|
||||||
end=end)
|
end=end)
|
||||||
|
|
||||||
|
check_fields = ['sid', 'open', 'high', 'low', 'close',
|
||||||
|
'volume', 'price']
|
||||||
source = DataPanelSource(data)
|
source = DataPanelSource(data)
|
||||||
|
stocks_iter = cycle(stocks)
|
||||||
for event in source:
|
for event in source:
|
||||||
self.assertTrue('sid' in event)
|
for check_field in check_fields:
|
||||||
self.assertTrue('open' in event)
|
self.assertIn(check_field, event)
|
||||||
self.assertTrue('high' in event)
|
|
||||||
self.assertTrue('low' in event)
|
|
||||||
self.assertTrue('close' in event)
|
|
||||||
self.assertTrue('volume' in event)
|
|
||||||
self.assertTrue('price' in event)
|
|
||||||
self.assertTrue(isinstance(event['volume'], (int, long)))
|
self.assertTrue(isinstance(event['volume'], (int, long)))
|
||||||
|
self.assertEqual(stocks_iter.next(), event['sid'])
|
||||||
|
|||||||
@@ -134,8 +134,9 @@ class DataPanelSource(DataSource):
|
|||||||
return self.arg_string
|
return self.arg_string
|
||||||
|
|
||||||
def raw_data_gen(self):
|
def raw_data_gen(self):
|
||||||
for sid, dataframe in self.data.iteritems():
|
for dt in self.data.major_axis:
|
||||||
for dt, series in dataframe.iterrows():
|
df = self.data.major_xs(dt)
|
||||||
|
for sid, series in df.iterkv():
|
||||||
if sid in self.sids:
|
if sid in self.sids:
|
||||||
event = {
|
event = {
|
||||||
'dt': dt,
|
'dt': dt,
|
||||||
|
|||||||
Reference in New Issue
Block a user