votes up 1

`vectorized` must be `True` or `False`.

Package:
scipy
github stars 8546
Exception Class:
ValueError

Raise code

def _bootstrap_iv(data, statistic, vectorized, paired, axis, confidence_level,
                  n_resamples, batch, method, random_state):
    """Input validation and standardization for `bootstrap`."""

    if vectorized not in {True, False}:
        raise ValueError("`vectorized` must be `True` or `False`.")

    if not vectorized:
        statistic = _vectorize_statistic(statistic)

    axis_int = int(axis)
    if axis != axis_int:
        raise ValueError("`axis` must be an integer.")
ūüė≤ Agile task management is now easier than calling a taxi. #Tracklify
ūüôŹ Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this ūüė†, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 2 votes down

The parameter vectorized expects a boolean type. If a string value is given an error is raised.

Reproducing the error:

pipenv install scipy numpy

import numpy as np
rng = np.random.default_rng()
from scipy.stats import norm
dist = norm(loc=2, scale=4)  # our "unknown" distribution
data = dist.rvs(size=100, random_state=rng,)
print(data.shape,"\n\n")
from scipy.stats import bootstrap
data = (data,)  # samples must be in a sequence
res = bootstrap(data, np.std,vectorized="True", confidence_level=0.9,random_state=rng)
print(res.confidence_interval)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-36606821c6b2> in <module>()
      7 from scipy.stats import bootstrap
      8 data = (data,)  # samples must be in a sequence
----> 9 res = bootstrap(data, np.std,vectorized="True", confidence_level=0.9,random_state=rng)
     10 print(res.confidence_interval)

/usr/local/lib/python3.7/dist-packages/scipy/stats/_bootstrap.py in bootstrap(data, statistic, vectorized, paired, axis, confidence_level, n_resamples, batch, method, random_state)
    418     args = _bootstrap_iv(data, statistic, vectorized, paired, axis,
    419                          confidence_level, n_resamples, batch, method,
--> 420                          random_state)
    421     data, statistic, vectorized, paired, axis = args[:5]
    422     confidence_level, n_resamples, batch, method, random_state = args[5:]

/usr/local/lib/python3.7/dist-packages/scipy/stats/_bootstrap.py in _bootstrap_iv(data, statistic, vectorized, paired, axis, confidence_level, n_resamples, batch, method, random_state)
    115 
    116     if vectorized not in {True, False}:
--> 117         raise ValueError("`vectorized` must be `True` or `False`.")
    118 
    119     if not vectorized:

ValueError: `vectorized` must be `True` or `False`.

Fixed:

import numpy as np
rng = np.random.default_rng()
from scipy.stats import norm
dist = norm(loc=2, scale=4)  # our "unknown" distribution
data = dist.rvs(size=100, random_state=rng,)
print(data.shape,"\n\n")
from scipy.stats import bootstrap
data = (data,)  # samples must be in a sequence
res = bootstrap(data, np.std,vectorized=True, confidence_level=0.9,random_state=rng)
print(res.confidence_interval)

(100,) 


ConfidenceInterval(low=3.8970533153782227, high=4.913762711731281)


Aug 23, 2021 kellemnegasi answer
kellemnegasi 30.0k

Add a possible fix

Please authorize to post fix