vincentarelbundock / pymarginaleffects

GNU General Public License v3.0
49 stars 9 forks source link

`transform` is slow #71

Closed vincentarelbundock closed 9 months ago

vincentarelbundock commented 9 months ago
def test_transform():
  c1 = avg_comparisons(m, comparison = "lnor")
  c2 = avg_comparisons(m, comparison = "lnor", transform = np.exp)
  all(np.exp(c1["estimate"]) == c2["estimate"])

Raises warning:

  x = x.with_columns(pl.col(col).apply(transform))
/home/vincent/repos/pymarginaleffects/marginaleffects/transform.py:13: PolarsInefficientMapWarning: 
Expr.map_elements is significantly slower than the native expressions API.
Only use if you absolutely CANNOT implement your logic otherwise.
Replace this expression...
  - pl.col("conf_low").map_elements(transform)
with this one instead:
  + pl.col("conf_low").exp()

  x = x.with_columns(pl.col(col).apply(transform))
/home/vincent/repos/pymarginaleffects/marginaleffects/transform.py:13: PolarsInefficientMapWarning: 
Expr.map_elements is significantly slower than the native expressions API.
Only use if you absolutely CANNOT implement your logic otherwise.
Replace this expression...
  - pl.col("conf_high").map_elements(transform)
with this one instead:
  + pl.col("conf_high").exp()

  x = x.with_columns(pl.col(col).apply(transform))