mito-ds / mito

The mitosheet package, trymito.io, and other public Mito code.
https://trymito.io
Other
2.29k stars 156 forks source link

Allow Python Snippets in Cells #202

Open aarondr77 opened 2 years ago

aarondr77 commented 2 years ago

As doing some analysis, I wanted to count the number of items in a list, each cell containing one list. This would've been straight forward to do in Python, but not possible in Mito.

Ideally, I would like to write a single statement that gets applied to every cell. For example, I was looking to write the python code len(column_name.split(',')). However, handling this might be constrictive to more advanced python usage.

There is a previous comment about this by @franceme in Discussions about this, however moving it here for visibility. Their specific post was:

As a user, I would like the ability to use Python snippets within formulas to create columns. Using Python for certain functions may make things easier in scenarios.

Ex: Create a column of File Extensions based on a column of Files Python: os.path.basename(dataframe['File'].str) or something similar

aarondr77 commented 2 years ago

Copying over @naterush's previous thoughts on implentation as well:

  1. We should be thoughtful about how we handle imports (e.g. os here would need to be in scope). Pandas has useful built ins as well.
  2. We shouldn't be restrictive on what this code can return - it would be useful to be able to compute intermediate results that aren't just series...
  3. How to handle multi-line statements?
twelsh37 commented 2 years ago

This could be a useful feature as you suggest but from a CyberSecurity point of view I wonder if that functionality could be subverted for other purposes.

I would hope that by allowing snippets to be run, that a Nefarious Threat Actor (Hows that for CyberSecurity terminology), couldn't run something like "import naughty_ module" and then in a second column be able to execute code utilising info loaded from the Naughty module.