Closed MarcoGorelli closed 1 month ago
I like this the first one more:
other = nw.from_dict({'a': [1,2,3]}, module=nw.get_native_namespace(nw_df))
as we can implement nw.DataFrame.from_dict
ourselves, while
other = nw.__compliant_namespace__().from_dict({'a': [1,2,3]})
would require that the native namespace has from_dict
function which is not necessarily true (arrow has pa.Table.from_pydict
).
In
formulaic
they do something like this:self.data
I think we need a way to do the same here. For example:
So like this, you pass
nw_df.__native_namespace__()
as an argument in thefrom_dict
call, and Narwhals knows to create anw.DataFrame
backed by the right object (here, a pandas dataframe)I dunno. We don't have the ability to just create dicts from nothing, so we need to slightly depart from the Polars signature, although the top-level Narwhals functions already depart from Polars anyway
anyone got a better API in mind?
one alternative which comes to mind:
which doesn't exactly thrill me