4

When typing the following code into the editor window, only some of the available items for autocomplete show up. That is to say that it should show .loc as an option but doesn't.

    import pandas as pd
    df = pd.read_csv('somecsvfile.csv')
    df.

code completion in editor window

When using the console in PyCharm with the same code, the full list shows up. (See the attached images)

code completion with the full list

I have invalidated caches and restarted. Further, it seems like another recommendation was to turn on Python Debugger -> Collect run-time types information for code insight. I did that as well and still nothing when in the editor window.

What really confuses me is that the code completion works in the console, but not the editor.

Any help would be greatly appreciated!

Brian
  • 41
  • 4
  • So when you try auto complete after `df.` does it properly show some of the functions specific to the DataFrame (i.e. not a part of `object`, `__builtins__`, etc)? – Anthony E May 02 '16 at 00:53
  • @AnthonyE, I of all the methods I checked in comparison to [this list](http://pandas.pydata.org/pandas-docs/version/0.17.1/generated/pandas.DataFrame.html) they were showing up. While I didn't check all of the methods, I did check all of the attributes. The only ones that didn't show up were `iat`, `iloc`, `loc`, and `ix`. I should state that `_ix` does show up. Does that answer your question? – Brian May 02 '16 at 02:28
  • Possible duplicate of [How do I import modules in pycharm?](https://stackoverflow.com/questions/19885821/how-do-i-import-modules-in-pycharm) – Pedram May 25 '19 at 05:57

2 Answers2

3

When you run it in the console it knows the type of df because it actually has it right there. It can even run dir(df) to know exactly what names are available. In the editor it isn't running the code so it has to guess the type by inspecting pd.read_csv which is much harder (often even impossible) because Python is so dynamic.

Alex Hall
  • 34,833
  • 5
  • 57
  • 89
  • 1
    Even if I define it as a DataFrame object, which is what `read_csv` returns, it doesn't provide the [full list](http://pandas.pydata.org/pandas-docs/version/0.17.1/generated/pandas.DataFrame.html) of methods and attributes. Attribute wise, it doesn't show `iat`, `iloc`, `loc`, `ix` although regarding `ix` it does show `_ix`. – Brian May 02 '16 at 02:37
0

I used to have this same problem. This was only happening for me in Linux. Note that this is possible and actually standard behavior in windows, so it can be done. Not sure if it is done using static analysis or a similar method.

I have since been able to fix it, I think what did it was defining the correct interpreter not only in the running/debugging configuration, but also in the defaults of the project (check File-->settings-->Project Interpreter and File-->default settings-->Project Interpreter)

I have now moved to the next problem, which is that auto-complete works for Python Console and File editing, but weirdly enough does not work for Debugging!...

ntg
  • 12,950
  • 7
  • 74
  • 95