Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove invalid auto completion options #237

Closed
baseliners opened this issue Nov 16, 2014 · 17 comments
Closed

Remove invalid auto completion options #237

baseliners opened this issue Nov 16, 2014 · 17 comments

Comments

@baseliners
Copy link

Hi DW,

Been trying out Anaconda with pandas in Python, and have a couple questions:

  1. When I create a pandas DataFrame df, and try "df." I get an auto completion list that consists of words in the file and methods for df. Is there any way to not get words in the file (the fact that I've typed in df. means I'm looking for DataFrame attributes/methods) and only get valid methods for the DF object? (I'm trying to get iPython-like behavior)
  2. I noticed that I do not get attributes for the DataFrame in the auto completion list. (e.g. "shape" doesn't show up if I type "sh"). Any way to enable attributes as well?

Currently, I get completion options that include the names of other DataFrames in my file, other variable names, etc. which are not valid candidates for completion.

I have the following in my Sublime settings:

{
  "auto_complete": true,
  "auto_complete_triggers": [
      {
          "selector": "source.python -string -comment -constant",
          "characters": ".",
      }
  ]
}

and the following in my Anaconda settings:

{
  "suppress_word_completions": true,
  "suppress_explicit_completions": true,
  "hide_snippets_on_completion": true
}

Thanks!

@DamnWidget
Copy link
Owner

Hi.

You shouldn't get any completion from words in your buffer as you have suppress_word_completions and suppress_explicit_completions set as true, not sure why you are stil getting any, try to restart your sublime text and let me know if you still get them.

About pandas, I know Jedi (the library that anaconda uses for autocompletion) had some problems with it in the past (as well as with other libraries that use some level of "magic" or tricks) so it's possible that you don't get all the autocompletions for some sort of objects in some libraries.

In the other hand, those kind of problems are already known in Jedi project and Anaconda is moving to more up to date versions of the stable Jedi library in the next release.

@baseliners
Copy link
Author

Thanks for the quick reply! I restarted ST and still see the words in the buffer when I type "df." .. any logs I can send to you? (btw, I do have anaconda_linting set to false but I presume that shouldn't affect this behavior)

Also, is there a dev branch of Anaconda that uses a newer version of Jedi that I can try?

@DamnWidget
Copy link
Owner

Hi again.

Depending on your operating system you can find logs in:

  • Linux: ~/.cache/jedi/<your_project_name>/anaconda_server.log
  • OS X: ~/Library/Caches/Jedi/<your_project_name>/anaconda_server.log
  • Windows: %APPDATA%\Jedi\Jedi<your_project_name>/anaconda_server.log

If you are using Linux or OS X, you can see how the plugin interacts with the JsonServer tailing the log file (tail -f in the file) so you can check if the autocompletion is being fired.

You don't need linting to fire autocompletion.

About Jedi, anaconda doesn't have a branch with a most up to date version of jedi but install a new version in your own copy of anaconda is pretty straightforward, you just need to donwload it from the Jedi repo in GitHub and replace the anaconda/anaconda_lib/jedi directory with the jedi directory in the version that you just downloaded, as far as I know, Jedi didn't broke their API compatibility so it should work fine.

@baseliners
Copy link
Author

Hi - I'm using OS X (10.10) and looked at the log file. It looks like no completions are returned when I type "df." or even "pd." but I do see a ton of completions when I do "np." .. here's what I see for "df.":

2014-11-16 11:46:15,509: INFO    : client requests: autocomplete
2014-11-16 11:46:15,559: INFO    : About push back to ST3: {"completions": [], "success": true, "uid": "4686e4aff4844b62b62f562f7e9d617b"}

I downloaded the Jedi master branch from Github and replaced the existing jedi folder in Anaconda, then restarted ST, and tried again but still no luck.. it appears the problem is w/ Jedi then? And it also looks like autocompletion doesn't work for the entire pandas package (since I couldn't do "pd." and get valid autocompletions either).

I also tried the dev branch of Jedi and that does raise an error when I try autocompletions for anything from pandas:

2014-11-16 11:57:09,084: ERROR   : The underlying Jedi library as raised an exception
2014-11-16 11:57:09,084: ERROR   : 'module' object has no attribute 'clear_caches'

I'll open an issue w/ Jedi, looks like they've added support for numpy/scipy/etc but I don't see an explicit mention of pandas.

@DamnWidget
Copy link
Owner

Hi.

The error that you get with the new version of jedi es because seems like they removed the clear_caches function and anaconda uses it to try to reduce the impact in memory consumption that Jedi has when parses big modules (like pandas).

Let me know what David tells you in Jedi's project.

@baseliners
Copy link
Author

Hi - I was looking at a few threads on the Jedi project, and found this thread. So I installed jedi via pip, then tried the following in a Python console:

print(jedi.Script('import pandas; df = pandas.DataFrame(); df.').completions())
print(jedi.Script('import pandas; pandas.').completions())

Both the above work and I see a bunch of completions. [Interestingly, the one in the thread with the numpy array "a." doesn't work but I suspect that fix has not yet been released.]

The version of jedi installed by pip is 0.8.1-final0. I don't see a 0.8.1-final0 tag in the jedi project but there is one w/ v0.8.1 so I tried replacing the jedi folder in Anaconda w/ the 0.8.1 jedi library. But I'm still not getting any autocompletions for pd. or df. in Anaconda. I'm wondering now if there's a problem w/ Anaconda and the way it interacts w/ jedi?

@DamnWidget
Copy link
Owner

Hi.

Can you take a look at the logs?

@baseliners
Copy link
Author

The Anaconda log looks the same as before (completions list is empty). Or did you mean a different log?

@DamnWidget
Copy link
Owner

Ok

I just test it myself in my AnacondaST3 installation and everything is working fine with the last version that is available on package control (1.3.4) there is a but anyway

I am using:

  • OS X 10.10 (yosemite)
  • ST3 build 3066
  • Anaconda v1.3.4

My hardware specifications are:
iMac (27-inch, Late 2013)
3.5 GHz Intel Core i7
24 GB 1600 MHz DDR3
3Tb Fusion Drive

This is the result of try to autocomplete pandas in my system:
screen shot 2014-11-16 at 22 13 54

But the index took a while to get built, the JsonServer loaded these specific modules:
screen shot 2014-11-16 at 22 21 04

After the index was built and anaconda cached it, is working properly everytime.

@baseliners
Copy link
Author

Hi - thanks a lot for the information and that screenshot! That helped me figure out what was going on. Turns out that ST3 doesn't pick up the python interpreter from my path, instead it was using the system one. I specified the python interpreter for ST3 (and also in Anaconda, though it looks like Anaconda does pick it up from the path) and it's working now! (I also ended up upgrading to ST3 3066 as I was using 3065).

One thing I noticed was that ST3 hangs quite a bit after I trigger an autocomplete (for reference, I haven't had ST3 hang at all for the last few months that I've been using it). I force quit the app and have the Console log/trace but can't seem to find a log file for ST3. Don't see anything related to the hang in Anaconda logs.

Think I can reproduce at will now - if I trigger an autocomplete, and then switch to another app before the results of the autocomplete show up, ST3 hangs. I take it this is an ST3 issue?

@DamnWidget
Copy link
Owner

I think your anaconda configuration is still wrong, ST shouldn't hangs at all.

Can you make a gist with your Anaconda.sublime-settings and your project configuration?

BTW: What do you mean with "I specified the python interpreter for ST3 "?

@baseliners
Copy link
Author

Hi,

This gist has my Anaconda and ST3 settings. Not sure what "project configuration" means but I don't have any specific configuration for this project.

I misspoke above .. it's not ST3 python interpreter, but the interpreter for SublimePythonIDE, which I'd installed a while back. I just removed this package since I don't think it's needed anymore given Anaconda. I can't reproduce the crash anymore! Thanks for catching this!

However, there is one new issue - when I type "pandas." the default completions show up for a second (or more if it's the first time after the Anaconda server starts up) before the Anaconda completions replace the default ones. I believe this is what the two suppress_* config options in Anaconda are for, so maybe there's a problem with my Anaconda config. I also tried adding the two suppress options to the Python.sublime-settings file but that did not work either.

@DamnWidget
Copy link
Owner

Hi

Yup, SublimePythonIDE and anaconda are not compatible at all :) The new issue that you are experimenting is not an issue, is normal anaconda behavior. Let me explain.

Anaconda is 100% asynchronous, that means that when ST3 send a signal saying "hey anaconda, I want you fire any autocompletion that you have to give me", anaconda just fires the autocompletion request into the anaconda's JsonServer and return back an empty response to ST3, that is because anaconda will never block waiting to perform any operation.

Then, when the anaconda's JsonServer has a result available, it return it back to ST3 and anaconda inject the results in the ST3 autocompletion firing it again.

As you already know, the first time that you are going to autocomplete something, Jedi build an index and then its contents are cached, with normal size Python packages that operation is almost instant so the user doesn't notice anything, but with Pandas, Numpy, PyQt, PySide, PyGTK there is a small delay between the anaconda plugin sends the request to the JsonServer and the request comes back with the new content.

The other option is totally block the ST3 interface while the index is being built that is in fact, not an option :)

Enjoy Anaconda and feel free to close this issue if you are satisfied already with the support.

Regards.

@baseliners
Copy link
Author

Hi - thanks for explaining the architecture. Few questions:

  1. I see that the Anaconda server shuts down after a 30mins inactivity period. Is this configurable? I'm guessing this has memory implications but would be nice to have this option if it's quick.
  2. The time it takes for Anaconda to make the 2nd/Nth call to Jedi and update the results seems a bit high given that Jedi already has a cache. Curious how iPython does this so quickly even for large packages like pandas.
  3. I use SublimeREPL and noticed that Anaconda has taken over the completions in the iPython console (via SublimeREPL) as well.. is there any way to disable Anaconda in the REPL?

@DamnWidget
Copy link
Owner

Hi again.

  1. Is not configurable now but can be added
  2. Hmmm, is instant for me, I tried in both my iMac and a DELL XPS 13 with Ubuntu GNU/Linux, btw, iPython is amazing
  3. There is no way right now but can be added as well

If you want to see 1 and 3 implemented, please, fill a couple of feature request issues.

Thanks.

@baseliners
Copy link
Author

Hi - will file the feature requests and yes, iPython is pretty cool! Thanks a lot for all your help and work, Anaconda is pretty cool too!

@baseliners
Copy link
Author

Update - it appears that Anaconda does not take over auto-completions in the iPython SublimeREPL.. I'm not sure how/why it did that day when I reported this but I can't reproduce it anymore. Will keep an eye out and update if I see otherwise but all good for now on that front.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants