Skip to content

Commit

Permalink
added some new transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoli committed Aug 1, 2024
1 parent 1bbc3d9 commit 8460b7b
Show file tree
Hide file tree
Showing 15 changed files with 1,039 additions and 252 deletions.
2 changes: 1 addition & 1 deletion gators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from typing import TypeVar

__version__ = "0.3.4"
__version__ = "0.3.5"
os.environ["PYARROW_IGNORE_TIMEZONE"] = "1"

DataFrame = TypeVar("Union[pd.DataFrame, ps.DataFrame, dd.DataFrame]")
Expand Down
6 changes: 3 additions & 3 deletions gators/binning/quantile_binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ def compute_bins(
bins_np : np.ndarray
Bin splits definition for NumPy.
"""
q = np.linspace(0.0, 1.0, self.n_bins + 1).tolist()
q = np.linspace(0.0, 1.0, self.n_bins + 1).tolist()[1:-1]
bins = X.quantile(q=q)
bins = util.get_function(bins).to_pandas(bins)
bins_dict = {
c: [-np.inf] + list(bins[c].unique())[1:-1] + [np.inf] for c in X.columns
c: [-np.inf] + list(bins[c].unique()) + [np.inf] for c in X.columns
}
# bins_np = bins.to_numpy()

pretty_bins_dict = {
k: [util.prettify_number(x, precision=2) for x in v]
for k, v in bins_dict.items()
Expand Down
48 changes: 24 additions & 24 deletions gators/binning/tests/test_quantile_binning_dd.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def data():
"[8.25, 41.94)",
],
"B__bin": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"D__bin": [
"(-inf, 26.3)",
Expand Down Expand Up @@ -100,12 +100,12 @@ def data_inplace():
"[8.25, 41.94)",
],
"B": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"C": ["a", "b", "c", "d", "e", "f"],
"D": [
Expand Down Expand Up @@ -170,12 +170,12 @@ def data_num():
"[8.25, 41.94)",
],
"B__bin": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"D__bin": [
"(-inf, 26.3)",
Expand Down Expand Up @@ -224,12 +224,12 @@ def data_num_inplace():
"[8.25, 41.94)",
],
"B": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"D": [
"(-inf, 26.3)",
Expand Down
96 changes: 48 additions & 48 deletions gators/binning/tests/test_quantile_binning_ks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def data_ks():
"[8.05, 53.1)",
],
"B__bin": [
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 1.0)",
"[1.0, inf)",
"[0.0, 1.0)",
"[0.0, 1.0)",
],
"D__bin": [
"(-inf, 26.0)",
Expand All @@ -54,12 +54,12 @@ def data_ks():
"[27.2, 30.0)",
],
"F__bin": [
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"[2.0, inf)",
"[3.0, inf)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[3.0, inf)",
],
}
)
Expand Down Expand Up @@ -90,12 +90,12 @@ def data_inplace_ks():
"[8.05, 53.1)",
],
"B": [
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 1.0)",
"[1.0, inf)",
"[0.0, 1.0)",
"[0.0, 1.0)",
],
"C": ["a", "b", "c", "d", "e", "f"],
"D": [
Expand All @@ -107,12 +107,12 @@ def data_inplace_ks():
"[27.2, 30.0)",
],
"F": [
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"[2.0, inf)",
"[3.0, inf)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[3.0, inf)",
],
}
)
Expand Down Expand Up @@ -155,12 +155,12 @@ def data_num_ks():
"[8.05, 53.1)",
],
"B__bin": [
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 1.0)",
"[1.0, inf)",
"[0.0, 1.0)",
"[0.0, 1.0)",
],
"D__bin": [
"(-inf, 26.0)",
Expand All @@ -171,12 +171,12 @@ def data_num_ks():
"[27.2, 30.0)",
],
"F__bin": [
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"[2.0, inf)",
"[3.0, inf)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[3.0, inf)",
],
}
)
Expand Down Expand Up @@ -206,12 +206,12 @@ def data_num_inplace_ks():
"[8.05, 53.1)",
],
"B": [
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"(-inf, inf)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 1.0)",
"[1.0, inf)",
"[0.0, 1.0)",
"[0.0, 1.0)",
],
"D": [
"(-inf, 26.0)",
Expand All @@ -222,12 +222,12 @@ def data_num_inplace_ks():
"[27.2, 30.0)",
],
"F": [
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"(-inf, 2.0)",
"[2.0, inf)",
"[2.0, inf)",
"[3.0, inf)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[1.0, 2.0)",
"[2.0, 3.0)",
"[3.0, inf)",
],
}
)
Expand Down
48 changes: 24 additions & 24 deletions gators/binning/tests/test_quantile_binning_pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def data():
"[8.25, 41.94)",
],
"B__bin": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"D__bin": [
"(-inf, 26.3)",
Expand Down Expand Up @@ -87,12 +87,12 @@ def data_inplace():
"[8.25, 41.94)",
],
"B": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"C": ["a", "b", "c", "d", "e", "f"],
"D": [
Expand Down Expand Up @@ -152,12 +152,12 @@ def data_num():
"[8.25, 41.94)",
],
"B__bin": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"D__bin": [
"(-inf, 26.3)",
Expand Down Expand Up @@ -203,12 +203,12 @@ def data_num_inplace():
"[8.25, 41.94)",
],
"B": [
"[0.5, inf)",
"[0.5, inf)",
"(-inf, 0.5)",
"[0.5, inf)",
"(-inf, 0.5)",
"(-inf, 0.5)",
"[1.0, inf)",
"[1.0, inf)",
"[0.0, 0.5)",
"[1.0, inf)",
"[0.0, 0.5)",
"[0.0, 0.5)",
],
"D": [
"(-inf, 26.3)",
Expand Down
Loading

0 comments on commit 8460b7b

Please sign in to comment.