-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
narwhals = Pandas + polars + ... #533
Comments
Hey, just wanted to stop by and say - thanks for your interest! Feel free to book some time on https://calendly.com/marcogorelli if you'd like to chat about how Narwhals could help PyFixest |
Hi both (@MarcoGorelli and @juanitorduz) - I've now thought about it for 15 minutes and I think Just some background on pyfixest and how it works with Data Frames: most of the data manipulation happens via the formulaic library, which requires an input %load_ext autoreload
%autoreload 2
import polars as pl
import pandas as pd
import pyfixest as pf
from formulaic import model_matrix
import narwhals as nw
data = pl.DataFrame(pf.get_data())
def feols(data):
if isinstance(data, pl.DataFrame):
data = data.to_pandas()
# model_matrix requires a pandas DataFrame and returns a pandas DataFrame
Y, X = model_matrix("Y ~ X1", data = data, output = "pandas")
# some more pandas manipulations
Y.dropna(inplace = True)
X.dropna(inplace = True)
return Y.to_numpy(), X.to_numpy() Via def feols_nw(data, use_polars = False):
data = nw.from_native(data)
# model_matrix requires a pandas DataFrame and returns a pandas DataFrame
Y, X = model_matrix("Y ~ X1", data = data.to_pandas(), output = "pandas")
if use_polars:
# another copy? potentially costly?
Y = nw.from_native(Y)
X = nw.from_native(X)
# some more pandas manipulations
Y.dropna(inplace = True)
X.dropna(inplace = True)
return Y.to_numpy(), X.to_numpy() |
Hey! Thanks for your explanation - if
Just to clarify, |
Naive question: It seems formulaic supports |
totally! |
Ciao! I am not sure if I have the time, but I'd be glad to support this narwhalification (h/t @FBruzzesi too). |
That would be amazing @baggiponte! One key step for this would be this PR to be merged into formulaic, and then we'd mostly have to port code from pandas to narwhals in the model_matrix function =) |
There's a nice new vignette in the |
Use https://github.com/narwhals-dev/narwhals to support pandas and polars!
This seems to be a very cool alternative to support various backends. See for example koaning/scikit-lego#671
The text was updated successfully, but these errors were encountered: