pwwang / datar

A Grammar of Data Manipulation in python
https://pwwang.github.io/datar/
MIT License
272 stars 17 forks source link

[ENH] Enable full compatibility with Pylance #184

Closed GitHunter0 closed 1 year ago

GitHunter0 commented 1 year ago

Feature Type

Problem Description

datar documentations are not fully discovered and displayed by Pylance as described in this issue https://github.com/microsoft/pylance-release/issues/4603

Feature Description

For example, being able to hover on glimpse in the MWE below and have the function info and docstring displayed:

import datar.all as d
import pandas as pd
df = pd.DataFrame({'x':[1,2,4]})
d.glimpse(df)

Additional Context

No response

pwwang commented 1 year ago

Should be enhanced by v0.13.0

image

However, this still has limitations for the dynamically added functions or objects, for example, additional functions that are added by a backend, and conflict names (python reserved names, i.e. filter). One should use filter_ instead. One could use filter with options(allow_conflict_names=True). However, the IDE will still only have hints for filter_.

GitHunter0 commented 1 year ago

Hey @pwwang , this is great, thank you.

Just a couple of points: When installing datar 0.13., I'm getting:

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.
datar-pandas 0.3.0 requires datar<0.13,>=0.12, but you have datar 0.13.0 which is incompatible.
datar-numpy 0.2.0 requires datar<0.13,>=0.12, but you have datar 0.13.0 which is incompatible.
Successfully installed datar-0.13.0

Also, when I run this

import datar.all as d
d.filter

I'm getting this error:

AttributeError: module 'datar.all' has no attribute 'filter'

However, d.filter_ runs fine.

python      : 3.10.4 | packaged by conda-forge | (main, Mar 30 2022, 08:38:02) [MSC v.1916 64 bit (AMD64)]
datar       : 0.13.0
simplug     : 0.3.2
executing   : 1.2.0
pipda       : 0.12.0
datar-numpy : 0.2.0
numpy       : 1.23.1
datar-pandas: 0.3.0
pandas      : 1.4.3
pwwang commented 1 year ago

Need to upgrade the backends as well.

d.filter to raise an error is by design, see: https://pwwang.github.io/datar/options/#allow_conflict_names

pwwang commented 1 year ago

The backends are now upgraded.

GitHunter0 commented 1 year ago

d.filter to raise an error is by design, see: https://pwwang.github.io/datar/options/#allow_conflict_names

Yes @pwwang , but if I'm importing datar as d and using filter as a function from source d like d.filter(), there should be no conflict of names at all, right? In this situation, options(allow_conflict_names=True) should not be necessary, don't you agree?

pwwang commented 1 year ago

Done with v0.13.1.

Note that d.filter still doesn't have IDE hints, as it's added dynamically.

GitHunter0 commented 1 year ago

Note that d.filter still doesn't have IDE hints, as it's added dynamically.

It's a pity, I hope Pylance gets dynamic support some day, many packages suffer from that same issue...

Done with v0.13.1.

Thank you

pwwang commented 1 year ago

That's the best we can do. It's (almost) impossible to do it dynamically because that requires us to run the whole code, which will bring uncontrollable side effects.

GitHunter0 commented 1 year ago

I understand and I appreciate the feedback, that's why I hope Pylance gets smarter.