ENH: update assets-db-error-msg

This commit is contained in:
Joe Jevnik
2016-07-27 23:28:02 -04:00
parent 4265a13edf
commit 6708ef1bdf
3 changed files with 49 additions and 13 deletions
+11 -5
View File
@@ -642,10 +642,16 @@ class AssetFinderTestCase(WithTradingCalendar, ZiplineTestCase):
self.assertEqual(
str(e.exception),
"Ambiguous ownership of 'MULTIPLE', multiple companies held this"
" ticker over the following ranges:\n"
"[('2010-01-01 00:00:00', '2012-01-01 00:00:00'),"
" ('2011-01-01 00:00:00', '2012-01-01 00:00:00')]",
"Ambiguous ownership for 1 symbol, multiple assets held the"
" following symbols:\n"
"MULTIPLE:\n"
" intersections: (('2010-01-01 00:00:00', '2012-01-01 00:00:00'),"
" ('2011-01-01 00:00:00', '2012-01-01 00:00:00'))\n"
" start_date end_date\n"
" sid \n"
" 1 2010-01-01 2012-01-01\n"
" 2 2010-01-01 2013-01-01\n"
" 3 2011-01-01 2012-01-01"
)
def test_lookup_generic(self):
@@ -1381,7 +1387,7 @@ class TestAssetDBVersioning(ZiplineTestCase):
downgrade(self.engine, 3)
metadata = sa.MetaData(conn)
metadata.reflect(bind=self.engine)
check_version_info(metadata.tables['version_info'], 3)
check_version_info(conn, metadata.tables['version_info'], 3)
self.assertFalse('exchange_full' in metadata.tables)
# now go all the way to v0
+28 -8
View File
@@ -226,19 +226,39 @@ def _split_symbol_mappings(df):
end_date.
"""
mappings = df[list(mapping_columns)]
ambigious = {}
for symbol in mappings.symbol.unique():
persymbol = mappings[mappings.symbol == symbol]
intersections = list(intersecting_ranges(
map(from_tuple, zip(persymbol.start_date, persymbol.end_date)),
))
intersections = list(intersecting_ranges(map(
from_tuple,
zip(persymbol.start_date, persymbol.end_date),
)))
if intersections:
raise ValueError(
'Ambiguous ownership of %r, multiple companies held this'
' ticker over the following ranges:\n%s' % (
symbol,
list(map(_format_range, intersections)),
ambigious[symbol] = (
intersections,
persymbol[['start_date', 'end_date']].astype('datetime64[ns]'),
)
if ambigious:
raise ValueError(
'Ambiguous ownership for %d symbol%s, multiple assets held the'
' following symbols:\n%s' % (
len(ambigious),
'' if len(ambigious) == 1 else 's',
'\n'.join(
'%s:\n intersections: %s\n %s' % (
symbol,
tuple(map(_format_range, intersections)),
# indent the dataframe string
'\n '.join(str(df).splitlines()),
)
for symbol, (intersections, df) in sorted(
ambigious.items(),
key=first,
),
),
)
)
return (
df.groupby(level=0).apply(_check_asset_group),
df[list(mapping_columns)],
+10
View File
@@ -1,3 +1,4 @@
from functools import reduce
import operator as op
from six import PY2
@@ -64,6 +65,15 @@ if PY2:
self.stop,
(', ' + str(self.step)) if self.step != 1 else '',
)
def __hash__(self):
return hash((type(self), self.start, self.stop, self.step))
def __eq__(self, other):
return reduce(
getattr(self, attr) == getattr(other, attr)
for attr in self.__slots__
)
else:
range = range