parmentelat / nbautoeval

Other
19 stars 4 forks source link

use with panda dataframe #34

Closed shalkya closed 3 years ago

shalkya commented 3 years ago

Hello again, I'm sorry if i missed something explaining how to use your module on panda dataframe directly.

I made the function called df_rule_of_five and i want to call it this way : new_df = df.apply(df_rule_of_five, axis=1) I don't know how to implement that in ExerciseFunction.

I could adapt the function df_rule_of_five so it doesn't require the use of .apply() But i get an error when doing exo_df_rule_of_five.correction(df_rule_of_five)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-116-4c8428f70886> in <module>
----> 1 exo_df_rule_of_five.correction(df_rule_of_five)

~/anaconda3/envs/teachopencadd/lib/python3.6/site-packages/nbautoeval/exercise_function.py in correction(self, student_function)
    233             # compare results
    234             is_ok = self.validate(expected, student_result)
--> 235             if not is_ok:
    236                 overall = False
    237             # render that run

~/anaconda3/envs/teachopencadd/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
   1476         raise ValueError("The truth value of a {0} is ambiguous. "
   1477                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1478                          .format(self.__class__.__name__))
   1479 
   1480     __bool__ = __nonzero__

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

I guess the code should check if input data is a df or not.

On a side note, dataframe display would be improved : Here is an example if i call the whole dataframe. image

I can solve (partially) the issue if i call only dataframe.head() image

parmentelat commented 3 years ago

Hey

The honest answer to that is that support for dataframes is clearly out of the current scope As you can see there is a limited support for numpy arrays in the form of the ExerciseFunctionNumpy class, but yes indeed supporting pandas dataframes would be a cool addition, it's just that I haven't had a chance to need that yet ;)

not necessarily a big amount of devel time, mind you

parmentelat commented 3 years ago

ExerciseFunctionPandas is available as of 1.7.0