diff --git a/protocol/purpose_and_scope.md b/protocol/purpose_and_scope.md index 3715e258..70dba143 100644 --- a/protocol/purpose_and_scope.md +++ b/protocol/purpose_and_scope.md @@ -50,24 +50,30 @@ aims to develop in the future. When that full API standard is implemented by dataframe libraries, the example above can change to: ```python -def get_df_module(df): +def get_compliant_df(df): """Utility function to support programming against a dataframe API""" if hasattr(df, '__dataframe_namespace__'): - # Retrieve the namespace - pdx = df.__dataframe_namespace__() + # Is already Standard-compliant DataFrame, nothing to do here. + pass + elif hasattr(df, '__dataframe_standard__'): + # Convert to Standard-compliant DataFrame. + df = df.__dataframe_standard__() else: # Here we can raise an exception if we only want to support compliant dataframes, # or convert to our default choice of dataframe if we want to accept (e.g.) dicts - pdx = pd - df = pd.DataFrame(df) - - return pdx, df + raise TypeError( + "Expected Standard-compliant DataFrame, or DataFrame with Standard-compliant implementation" + ) + return df def somefunc(df, ...): """`df` can be any dataframe conforming to the dataframe API standard""" - pdx, df = get_df_module(df) - # From now on, use `df` methods and `pdx` functions/objects + # Get Standard-compliant DataFrame. + df = get_compliant_df(df) + # Get Standard namespace (optional, only if you need methods from it). + namespace = df.__dataframe_namespace__() + # From now on, use `df` methods and `namespace` functions/objects ```