juba / pyobsplot

Observable Plot in Jupyter notebooks and Quarto documents
https://juba.github.io/pyobsplot/
MIT License
203 stars 7 forks source link

Make shorthand definition possible #18

Closed harrylojames closed 2 months ago

harrylojames commented 1 year ago

Hi,

In line with having a syntax as close as possible to javascript it would nice to be able to use the shorthand syntax as seen here.

import pandas as pd
from pyobsplot import Plot

df = pd.DataFrame({'Date': {0: '1880-01-01', 1: '1880-02-01'}, 'Anomaly': {0: -0.3, 1: -0.21}})
Plot.lineY(df, {"x": "Date", "y": "Anomaly"}).plot()
AttributeError                            Traceback (most recent call last)
Cell In[15], line 5
      2 from pyobsplot import Plot
      4 df = pd.DataFrame({'Date': {0: '1880-01-01', 1: '1880-02-01'}, 'Anomaly': {0: -0.3, 1: -0.21}})
----> 5 Plot.lineY(df, {"x": "Date", "y": "Anomaly"}).plot()

AttributeError: 'dict' object has no attribute 'plot'

Not sure how feasible this is and not a dealbreaker for me but thought it was worth noting in case it wasn't on the radar.

Many thanks,

Harry

juba commented 1 year ago

I'm not sure I would be able to implement this given the way python Plot methods are automatically generated, but this is indeed a very valid suggestion.

I keep this open, thanks for the idea !

juba commented 2 months ago

This shortcut syntax should now be available in the development version (I have yet to add it to the documentation). It was much easier to implement than I thought.

Thanks again for the suggestion (and your patience).

I'm closing the issue for now but don't hesitate to reopen it if you encounter any problem.