5

Using the following code example:

import pandas as pd from typing import Dict class Test: def __init__(self, df : pd.DataFrame) -> None: self.df = df def example(self, replacements : Dict[str, str]) -> None: self.df = self.df.rename(columns = replacements) 

Nvim displays:

enter image description here

rename is definitely a member of a dataframe object, and Pyright is aware of the venv I'm using as I get pandas completion:

enter image description here

I even get completion of the member which is an "error"

enter image description here

I'm not sure what exactly to check / post to make things clearer as I'm only recently setting this up.

I think the question is basically - how do I get the LSP to recognise that this is a "known" member? I'm not sure how it determines that, I'd like to be able to use pandas without so many errors though.

"Which plugin do you have installed?"

These are the plugins that I have installed:

 use "wbthomason/packer.nvim" -- have packer manage itself use "nvim-lua/popup.nvim" -- implementation of the popup api from vim in nvim use "nvim-lua/plenary.nvim" -- useful lua functions use "windwp/nvim-autopairs" -- integrates with other stuff.... autocmp and whatever use "kyazdani42/nvim-web-devicons" use "kyazdani42/nvim-tree.lua" use "lunarvim/colorschemes" use "folke/tokyonight.nvim" use "tanvirtin/monokai.nvim" use "hrsh7th/nvim-cmp" -- completion plugin use "hrsh7th/cmp-buffer" -- buffer completions use "hrsh7th/cmp-path" -- path completions use "hrsh7th/cmp-cmdline" -- cmdline completions use "hrsh7th/cmp-nvim-lua" -- cmdline completions use "hrsh7th/cmp-nvim-lsp" -- lsp completions use "saadparwaiz1/cmp_luasnip" -- snippet completions completions use "L3MON4D3/Luasnip" -- snippet engine use "rafamadriz/friendly-snippets" -- snippet engine use "neovim/nvim-lspconfig" -- enable lsp use "williamboman/nvim-lsp-installer" -- simple to use language server installer use "jose-elias-alvarez/null-ls.nvim" -- for formatters and linters use "nvim-telescope/telescope.nvim" use 'nvim-telescope/telescope-media-files.nvim' use "lewis6991/gitsigns.nvim" 

"What is the lsp configuration?"

-- Following: https://github.com/neovim/nvim-lspconfig#Suggested-configuration -- See `:help vim.diagnostic.*` for documentation on any of the below functions local opts = { noremap=true, silent=true } -- NOTE: Not sure about these atm -- vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) -- vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) -- vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) -- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) -- Enable completion triggered by <c-x><c-o> vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. -- See `:help vim.lsp.*` for documentation on any of the below functions local bufopts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set('n', '<space>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, bufopts) vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts) end local lsp_flags = { -- This is the default in Nvim 0.7+ debounce_text_changes = 150, } require('lspconfig')['pyright'].setup{ on_attach = on_attach, flags = lsp_flags, } 
5
  • 1
    Can tell us which plugin you have installed? e.g. It could be that pyright knows panda but ALE do not. Commented Aug 21, 2022 at 16:46
  • 1
    @VivianDeSmedt thanks - i updated the post with the plugins that are installed. Commented Aug 21, 2022 at 18:21
  • Thanks. Maybe could you try to reproduce the problem only with the lsp plugin to be sure the completion plugin doesn't interfere. I see no reference to pyright. Is pyright part of the configuration of lsp? What is the lsp configuration? Commented Aug 21, 2022 at 18:48
  • 2
    How to debug my vimrc Commented Aug 21, 2022 at 19:44
  • I just started using Lunarvim and am running into a similar issue. I'm new to typing in Python which makes it even more confusinger. Did you ever resolve this issue? Commented Mar 23, 2023 at 19:59

1 Answer 1

2

My problem was that to detect the correct signatures, I needed the pandas-stubs package installed. Unfortunately, this is not packaged in my distribution.

My solution is to create a virtual environment and activate it when editing pandas/numpy programs.

The process is quite straightforward (this is on Ubuntu 24.04.1).

python3 -m venv ~/lib/venvs/pystubs ` cd ~/lib/venvs/pystubs source ./bin/activate pip3 install pandas-stubs 

This gives an error about incompatible versions of matplotlib (due to the usage of --system-site-packages:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. types-seaborn 0.13 requires matplotlib>=3.8, but you have matplotlib 3.6.3 which is incompatible. 

...that I think can be resolved by removing the --system... thing and sacrificing quite a lot of disk space, but the good things is that it works... you can activate the new environment when editing with

source ~/lib/venvs/pystubs/bin/activate 

and then editing from that shell works:

enter image description here

Notice that, for whatever reason, if you do a full virtualenv (without the --system-site-packages) you need to install also

pip3 install neovim 

in the virtuaenv, and all the libraries:

Modules not found in the virtualenv

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.