nicolaskruchten / jupyter_pivottablejs

Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js
http://nicolas.kruchten.com/content/2015/09/jupyter_pivottablejs/
Other
687 stars 88 forks source link

filter function crashes pivottable rendering #26

Closed PeteW closed 7 years ago

PeteW commented 7 years ago

Consider:

    pivot_ui(df, filter='function (x){return true;}', rows=['dim1'],cols=['timespan'],  vals=['count'],aggregatorName='Sum',rendererName = "Line Chart")

Problem is filter is a reserved keyword in python thus triggering syntax error. Need to add a special case in the pivot_ui method to handle filter parameter.

PeteW commented 7 years ago

On a side note I wanted to take a moment and thank you for your wonderful library. These really bring notebooks to life.

nicolaskruchten commented 7 years ago

You're welcome, I'm glad you like this library!

Regarding your request, a couple of comments:

  1. it's not actually possible at the moment to specify Javascript functions in strings and pass them in this way: they will get passed in as strings and not functions! I could envision a PR that would make this possible based on whether or not the string starts with the token function but this is not currently supported, and it feels kind of gross to have a Python library that accepts arbitrary Javascript strings ;)
  2. In the specific case of filtering, Pandas is a far more powerful tool than PivotTable.js so instead of passing in df and a filter function, you could pass in df.query("x > y and b*a < 10+c") or something like that.