@@ -149,6 +149,40 @@ def _num_samples(x):
149
149
return len (x )
150
150
151
151
152
+ def _shape_repr (shape ):
153
+ """Return a platform independent representation of an array shape
154
+
155
+ Under Python 2, the `long` type introduces an 'L' suffix when using the
156
+ default %r format for tuples of integers (typically used to store the shape
157
+ of an array).
158
+
159
+ Under Windows 64 bit (and Python 2), the `long` type is used by default
160
+ in numpy shapes even when the integer dimensions are well below 32 bit.
161
+ The platform specific type causes string messages or doctests to change
162
+ from one platform to another which is not desirable.
163
+
164
+ Under Python 3, there is no more `long` type so the `L` suffix is never
165
+ introduced in string representation.
166
+
167
+ >>> _shape_repr((1, 2))
168
+ '(1, 2)'
169
+ >>> one = 2 ** 64 / 2 ** 64 # force an upcast to `long` under Python 2
170
+ >>> _shape_repr((one, 2 * one))
171
+ '(1, 2)'
172
+ >>> _shape_repr((1,))
173
+ '(1,)'
174
+ >>> _shape_repr(())
175
+ '()'
176
+ """
177
+ if len (shape ) == 0 :
178
+ return "()"
179
+ joined = ", " .join ("%d" % e for e in shape )
180
+ if len (shape ) == 1 :
181
+ # special notation for singleton tuples
182
+ joined += ','
183
+ return "(%s)" % joined
184
+
18
D374
5
+
152
186
def check_memory (memory ):
153
187
"""Check that ``memory`` is joblib.Memory-like.
154
188
@@ -537,20 +571,21 @@ def check_array(array, accept_sparse=False, accept_large_sparse=True,
537
571
_assert_all_finite (array ,
538
572
allow_nan = force_all_finite == 'allow-nan' )
539
573
574
+ shape_repr = _shape_repr (array .shape )
540
575
if ensure_min_samples > 0 :
541
576
n_samples = _num_samples (array )
542
577
if n_samples < ensure_min_samples :
543
578
raise ValueError ("Found array with %d sample(s) (shape=%s) while a"
544
579
" minimum of %d is required%s."
545
- % (n_samples , array . shape , ensure_min_samples ,
580
+ % (n_samples , shape_repr , ensure_min_samples ,
546
581
context ))
547
582
548
583
if ensure_min_features > 0 and array .ndim == 2 :
549
584
n_features = array .shape [1 ]
550
585
if n_features < ensure_min_features :
551
586
raise ValueError ("Found array with %d feature(s) (shape=%s) while"
552
587
" a minimum of %d is required%s."
553
- % (n_features , array . shape , ensure_min_features ,
588
+ % (n_features , shape_repr , ensure_min_features ,
554
589
context ))
555
590
556
591
if warn_on_dtype and dtype_orig is not None and array .dtype != dtype_orig :
0 commit comments