Skip to content
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

Add support for polars #90

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Help mypy with to_numpy.
  • Loading branch information
kklein committed Sep 5, 2024
commit 1ef9dfdc1698a5ae6ddb64a8171eecc57a5f7108
15 changes: 8 additions & 7 deletions metalearners/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ def convert_and_pad_propensity_score(
propensity score per variant. The expansion assumes that the provided scores are
those for the second variant.
"""
if isinstance(propensity_scores, pd.Series) or isinstance(
propensity_scores, pd.DataFrame
):
propensity_scores = propensity_scores.to_numpy()
p_is_1d = len(propensity_scores.shape) == 1 or propensity_scores.shape[1] == 1
if isinstance(propensity_scores, np.ndarray):
np_propensity_scores = propensity_scores
else:
np_propensity_scores = propensity_scores.to_numpy()

p_is_1d = len(np_propensity_scores.shape) == 1 or np_propensity_scores.shape[1] == 1
if n_variants == 2 and p_is_1d:
propensity_scores = np.c_[1 - propensity_scores, propensity_scores]
return propensity_scores
np_propensity_scores = np.c_[1 - np_propensity_scores, np_propensity_scores]
return np_propensity_scores


def get_n_variants(propensity_scores: Matrix) -> int:
Expand Down