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
Function to show the translation to pandas
#116
Comments
No, not now. We actually had a discussion before: #48 (comment) |
@pwwang , I think that discussion is about a different issue, porting What I'm proposing here is a different matter, not related to SQL or dbplyr, it is just a function to show the translation of Did you get what I mean? |
Nope. Could you define "datar commands" and "pandas commands"? |
@pwwang , basically, the import datar.all as d
from datar.all import f
import pandas as pd
#
d.tibble(x=range(1,5), y=range(2,6)) >> \
d.filter(f.x.isin([2,4])) >> \
d.show_query()
# Would return something like:
'''
df = pd.DataFrame({'x': range(1,5), 'y': range(2,6)})
df[df['x'].isin([2,4])]
''' Please ask if it is still not clear what I mean. |
I see what you mean now. But I am not sure if this is feasible since the operations are not 1:1 or 1:N mappings. It could be way more complicated than you think. Quite a lot of verbs/functions are not simply composed of just a couple of pandas operations. For example: from datar.all import glimpse
from datar.datasets import iris
iris >> glimpse()
# Rows: 150
# Columns: 5
# . Sepal_Length <float64> 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0,…
# . Sepal_Width <float64> 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4,…
# . Petal_Length <float64> 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5,…
# . Petal_Width <float64> 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2,…
# . Species <object> 'setosa', 'setosa', 'setosa', 'setosa',… It's almost "impossible" to remap it to simple and clean pandas commands. |
For sure @pwwang , I'm aware of the complexity and that a one to one map is impossible. I was not expecting to consistently get clean pandas commands but rather a look on what operations are being executed in the backend (pandas or not). It is just an idea to see |
It looks like you want to reach the implementation of how I wouldn't say it's really impossible to provide the source code of implementation, but to make it runnable with raw I am closing it for now, but we can keep an eye on this for sure. |
@pwwang , just for the sake of completeness. I will let an example below of an R package that shows the translation from
It shows that the
|
Good mention. |
Hey @pwwang , does
datar
have a function to display the translation topandas
commands?I believe it would be a very useful addition for many reasons, one being that it would help a lot
datar
andpandas
users to work together in a project.In R, an analogous function would be
dplyr::show_query()
, which shows the translation toSQL
, like in the example below:Thank you
The text was updated successfully, but these errors were encountered: