Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Numpy analysis is inconsistent from run to run #1414

Closed
MikhailArkhipov opened this issue Aug 7, 2019 · 7 comments
Closed

Numpy analysis is inconsistent from run to run #1414

MikhailArkhipov opened this issue Aug 7, 2019 · 7 comments
Assignees
Labels
bug Something isn't working feature: analysis feature: imports package: numpy Issues specific to Numpy

Comments

@MikhailArkhipov
Copy link

MikhailArkhipov commented Aug 7, 2019

import numpy
numpy.

Run analysis, look at icons in the completion list. Reload and run again - you get different set. Ex, 3 sequential runs (look at AxisError, ALLOW_THREADS, DataSource). [abc] icon actually means Unknown

image

image

image

@MikhailArkhipov
Copy link
Author

I'll see if I can get better repro

@AlexanderSher
Copy link
Contributor

Here is the minimal test that reproduces the issue:

        [TestMethod, Priority(0)]
        public async Task LoopImports_Variables() {
            var module1Code = @"
class A1: 
    def M1(self): return 0; pass

from module2 import y3
x = y3.M3()
";
            var module2Code = @"
from module1 import A1
y1 = A1()
from module3 import A3
y3 = A3()
";
            var module3Code = @"
class A3:
    def M3(self): return '0'; pass

from module2 import y1
z = y1.M1()
";

            var appCode = @"
from module1 import x
from module3 import z

x.
z.";

            var module1Uri = TestData.GetTestSpecificUri("module1.py");
            var module2Uri = TestData.GetTestSpecificUri("module2.py");
            var module3Uri = TestData.GetTestSpecificUri("module3.py");
            var appUri = TestData.GetTestSpecificUri("app.py");

            var root = Path.GetDirectoryName(appUri.AbsolutePath);
            await CreateServicesAsync(root, PythonVersions.LatestAvailable3X);
            var rdt = Services.GetService<IRunningDocumentTable>();
            var analyzer = Services.GetService<IPythonAnalyzer>();

            rdt.OpenDocument(module1Uri, module1Code);
            rdt.OpenDocument(module2Uri, module2Code);
            rdt.OpenDocument(module3Uri, module3Code);

            var app = rdt.OpenDocument(appUri, appCode);
            await analyzer.WaitForCompleteAnalysisAsync();
            var analysis = await app.GetAnalysisAsync(-1);

            var cs = new CompletionSource(new PlainTextDocumentationSource(), ServerSettings.completion);
            var comps = cs.GetCompletions(analysis, new SourceLocation(5, 3));
            comps.Should().HaveLabels("capitalize");

            comps = cs.GetCompletions(analysis, new SourceLocation(6, 3));
            comps.Should().HaveLabels("bit_length");
        }

@AeneasZhu
Copy link

How to fix #1635 ?

@MikhailArkhipov
Copy link
Author

There is no consistent fix. The problem is that analysis sometimes produces results as I showed and sometimes does not. It involves concurrency and circular dependencies between modules in numpy. You may try reloading window and see if the analysis result is different.

@MikhailArkhipov
Copy link
Author

Partial PR #1584, parts can be reused.

@MikhailArkhipov
Copy link
Author

In favor of #1666

@jakebailey
Copy link
Member

Closing per #1686.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working feature: analysis feature: imports package: numpy Issues specific to Numpy
Projects
None yet
Development

No branches or pull requests

7 participants