0

In scipyt.stats we have the variable binom Somehow autocomplete in vscode doesn't seem to find it. In pycharm the autocomplete works fine. Any pointers as though why it is so ? Also just some sample code with binom as follows from scipy.stats import binom; binom.rvs(10,0.5,size=12).

VS code Screenshot

sayan dasgupta
  • 1,084
  • 6
  • 15
  • Make sure you selected the right python interpreter (F1 > Python: Select Interpreter). Also make sure you installed the Python extension. – Flo Aug 31 '21 at 16:11

2 Answers2

2

This is the __init__.py file under scipy.stats package:

from .stats import *
from .distributions import *

from .morestats import *
from ._binomtest import binomtest
from ._binned_statistic import *
from .kde import gaussian_kde
from . import mstats
from . import qmc
from ._multivariate import *
from . import contingency
from .contingency import chi2_contingency
from ._bootstrap import bootstrap
from ._entropy import *
from ._hypotests import *
from ._rvs_sampling import rvs_ratio_uniforms, NumericalInverseHermite
from ._page_trend_test import page_trend_test
from ._mannwhitneyu import mannwhitneyu

__all__ = [s for s in dir() if not s.startswith("_")]  # Remove dunders.

from scipy._lib._testutils import PytestTester

test = PytestTester(__name__)
del PytestTester

It does not contain: from ._discrete_distns import binom. So the Pylance will not prompt it in the suggestion list.

You can import it through: from scipy.stats._discrete_distns import binom like bwdm suggested above.

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214
Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
  • This looks like a flaw in Pylance. For historical reasons, the import of the name `binom` into the `scipy.stats` namespace goes through a couple levels of indirection (`__init__.py` imports from `distributions.py`, and `distributions.py` imports from `_discrete_distns.py`). The end result, however, is that `binom` is a public name in the `scipy.stats` namespace. The leading underscore in `_discrete_distns.py` is there precisely to *avoid* having users import directly from that module; being private, it is potentially subject to change in future versions of SciPy. – Warren Weckesser Sep 02 '21 at 16:53
  • 1
    To be more definitive: in general, you should *not* import from `scipy.stats._discrete_distns`. The contents of that private module could be changed, or the module itself could be renamed or removed at any point in the future. – Warren Weckesser Oct 29 '21 at 21:39
1

It seems that binom is defined in the submodule scipy/stats/_discrete_distns, which is imported by the main module in scipy/stats/__init__. I believe that variable doesn't get autocomplete because it's defined in an internal module of scipy.stats (_discrete_distns has the underscore prefix), i.e. VS Code treats it as "private" in this case.

I tried a few extensions like IntelliCode and Pylance, but it still doesn't autocomplete binom from scipy/stats. The only way I managed to get it to autocomplete was by importing scipy/stats/_discrete_distns directly.

bwdm
  • 793
  • 7
  • 17