Skip to content

Commit 55fa1de

Browse files
Joe Jevnikllllllllll
authored andcommitted
ENH: improve multidimensional dataset error messages
1 parent f8ff7db commit 55fa1de

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

tests/pipeline/test_multidimensional_dataset.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,15 @@ def expect_slice_fails(*args, **kwargs):
138138
# insufficient positional
139139
expect_slice_fails(
140140
expected_msg=(
141-
'no coordinate provided for the following dimensions:'
141+
'no coordinate provided to MD for the following dimensions:'
142142
' dim_0, dim_1'
143143
),
144144
)
145145
expect_slice_fails(
146146
'a',
147147
expected_msg=(
148-
'no coordinate provided for the following dimension: dim_1'
148+
'no coordinate provided to MD for the following dimension:'
149+
' dim_1'
149150
),
150151
)
151152

@@ -158,22 +159,32 @@ def expect_slice_fails(*args, **kwargs):
158159
# mismatched keys
159160
expect_slice_fails(
160161
dim_2='??',
161-
expected_msg='MD does not have the following dimension: dim_2',
162+
expected_msg=(
163+
'MD does not have the following dimension: dim_2\n'
164+
'Valid dimensions are: dim_0, dim_1'
165+
),
162166
)
163167
expect_slice_fails(
164168
dim_1='??', dim_2='??',
165-
expected_msg='MD does not have the following dimension: dim_2',
169+
expected_msg=(
170+
'MD does not have the following dimension: dim_2\n'
171+
'Valid dimensions are: dim_0, dim_1'
172+
),
166173
)
167174
expect_slice_fails(
168175
dim_0='??', dim_1='??', dim_2='??',
169-
expected_msg='MD does not have the following dimension: dim_2',
176+
expected_msg=(
177+
'MD does not have the following dimension: dim_2\n'
178+
'Valid dimensions are: dim_0, dim_1'
179+
),
170180
)
171181

172182
# the extra keyword dims should be sorted
173183
expect_slice_fails(
174184
dim_3='??', dim_2='??',
175185
expected_msg=(
176-
'MD does not have the following dimensions: dim_2, dim_3'
186+
'MD does not have the following dimensions: dim_2, dim_3\n'
187+
'Valid dimensions are: dim_0, dim_1'
177188
),
178189
)
179190

@@ -192,20 +203,28 @@ def expect_slice_fails(*args, **kwargs):
192203

193204
expect_slice_fails(
194205
'not-in-0', 'c',
195-
expected_msg="'not-in-0' is not a value along the dim_0 dimension",
206+
expected_msg=(
207+
"'not-in-0' is not a value along the dim_0 dimension of MD"
208+
),
196209
)
197210
expect_slice_fails(
198211
dim_0='not-in-0', dim_1='c',
199-
expected_msg="'not-in-0' is not a value along the dim_0 dimension",
212+
expected_msg=(
213+
"'not-in-0' is not a value along the dim_0 dimension of MD"
214+
),
200215
)
201216

202217
expect_slice_fails(
203218
'a', 'not-in-1',
204-
expected_msg="'not-in-1' is not a value along the dim_1 dimension",
219+
expected_msg=(
220+
"'not-in-1' is not a value along the dim_1 dimension of MD"
221+
),
205222
)
206223
expect_slice_fails(
207224
dim_0='a', dim_1='not-in-1',
208-
expected_msg="'not-in-1' is not a value along the dim_1 dimension",
225+
expected_msg=(
226+
"'not-in-1' is not a value along the dim_1 dimension of MD"
227+
),
209228
)
210229

211230
def test_inheritence(self):

zipline/pipeline/data/dataset.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
LoadableTerm,
2222
validate_dtype,
2323
)
24+
from zipline.utils.formatting import s, plural
2425
from zipline.utils.input_validation import ensure_dtype, expect_types
2526
from zipline.utils.numpy_utils import NoDefaultMissingValue
2627
from zipline.utils.preprocess import preprocess
@@ -648,8 +649,8 @@ class SomeDataSet(MultiDimensionalDataSet):
648649
sid :: int64
649650
asof_date :: datetime64[ns]
650651
timestamp :: datetime64[ns]
651-
dimension_0 :: {'a', 'b', 'c'}
652-
dimension_1 :: {'d', 'e', 'f'}
652+
dimension_0 :: str
653+
dimension_1 :: str
653654
column_0 :: float64
654655
column_1 :: bool
655656
@@ -685,21 +686,23 @@ def _canonical_key(cls, args, kwargs):
685686
if not set(kwargs) <= dimensions_set:
686687
extra = sorted(set(kwargs) - dimensions_set)
687688
raise TypeError(
688-
'%s does not have the following dimension%s: %s' % (
689+
'%s does not have the following %s: %s\n'
690+
'Valid dimensions are: %s' % (
689691
cls.__name__,
690-
's' if len(extra) > 1 else '',
692+
s('dimension', extra),
691693
', '.join(extra),
694+
', '.join(extra_dims),
692695
),
693696
)
694697

695698
if len(args) > len(extra_dims):
696699
raise TypeError(
697-
'%s has %d extra dimension%s but %d %s given' % (
700+
'%s has %d extra %s but %d %s given' % (
698701
cls.__name__,
699702
len(extra_dims),
700-
's' if len(extra_dims) > 1 else '',
703+
s('dimension', extra_dims),
701704
len(args),
702-
'were' if len(args) != 1 else 'was',
705+
plural('was', 'were', args),
703706
),
704707
)
705708

@@ -724,8 +727,9 @@ def _canonical_key(cls, args, kwargs):
724727
if missing:
725728
missing = sorted(missing)
726729
raise TypeError(
727-
'no coordinate provided for the following dimension%s: %s' % (
728-
's' if len(missing) > 1 else '',
730+
'no coordinate provided to %s for the following %s: %s' % (
731+
cls.__name__,
732+
s('dimension', missing),
729733
', '.join(missing),
730734
),
731735
)
@@ -735,7 +739,11 @@ def _canonical_key(cls, args, kwargs):
735739
for key, value in coords.items():
736740
if value not in cls.extra_dims[key]:
737741
raise ValueError(
738-
'%r is not a value along the %s dimension' % (value, key),
742+
'%r is not a value along the %s dimension of %s' % (
743+
value,
744+
key,
745+
cls.__name__,
746+
),
739747
)
740748

741749
return coords, tuple(coords.items())

0 commit comments

Comments
 (0)