-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add more aggregations/functions (#686)
Adds coalesce, ceil, clamp, exp, powf, floor.
- Loading branch information
1 parent
146c747
commit 555472e
Showing
24 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import kaskada as kd | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def source() -> kd.sources.CsvString: | ||
content = "\n".join( | ||
[ | ||
"time,key,m", | ||
"1996-12-19T16:39:57,A,5", | ||
"1996-12-19T16:39:58,B,100.0001", | ||
"1996-12-19T16:39:59,A,2.50", | ||
"1996-12-19T16:40:00,A,", | ||
"1996-12-19T16:40:01,A,0.99", | ||
"1996-12-19T16:40:02,A,1.01", | ||
] | ||
) | ||
return kd.sources.CsvString(content, time_column_name="time", key_column_name="key") | ||
|
||
|
||
def test_ceil(source, golden) -> None: | ||
m = source.col("m") | ||
golden.jsonl(kd.record({"m": m, "ceil_m": m.ceil()})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import kaskada as kd | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def source() -> kd.sources.CsvString: | ||
content = "\n".join( | ||
[ | ||
"time,key,m", | ||
"1996-12-19T16:39:57,A,5", | ||
"1996-12-19T16:39:58,B,100.0001", | ||
"1996-12-19T16:39:59,A,2.50", | ||
"1996-12-19T16:40:00,A,", | ||
"1996-12-19T16:40:01,A,0.99", | ||
"1996-12-19T16:40:02,A,1.01", | ||
] | ||
) | ||
return kd.sources.CsvString(content, time_column_name="time", key_column_name="key") | ||
|
||
|
||
def test_clamp_min_max(source, golden) -> None: | ||
m = source.col("m") | ||
golden.jsonl(kd.record({"m": m, "clamped_m": m.clamp(min=5, max=100)})) | ||
|
||
|
||
def test_clamp_min(source, golden) -> None: | ||
m = source.col("m") | ||
golden.jsonl(kd.record({"m": m, "clamped_min": m.clamp(min=5)})) | ||
|
||
|
||
def test_clamp_max(source, golden) -> None: | ||
m = source.col("m") | ||
golden.jsonl(kd.record({"m": m, "clamped_min": m.clamp(max=100)})) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def banking_source() -> kd.sources.CsvString: | ||
content = "\n".join( | ||
[ | ||
"time,key,current_balance,min_balance,max_balance", | ||
"1996-12-19T16:39:57,A,5.00,6.00,6.01", | ||
"1996-12-19T16:39:58,B,6.00,7.00,7.01", | ||
"1996-12-19T16:39:59,A,7.00,8.00,8.01", | ||
"1996-12-19T16:40:00,A,8.00,9.00,9.01", | ||
"1996-12-19T16:40:01,A,9.00,10.00,10.01", | ||
"1996-12-19T16:40:02,A,10.00,11.00,11.01", | ||
] | ||
) | ||
return kd.sources.CsvString(content, time_column_name="time", key_column_name="key") | ||
|
||
|
||
def test_clamp_banking_min_max(banking_source, golden) -> None: | ||
current_balance = banking_source.col("current_balance") | ||
min_balance = banking_source.col("min_balance") | ||
max_balance = banking_source.col("max_balance") | ||
golden.jsonl( | ||
kd.record( | ||
{ | ||
"current_balance": current_balance, | ||
"clamped_balance": current_balance.clamp( | ||
min=min_balance, max=max_balance | ||
), | ||
} | ||
) | ||
) | ||
|
||
|
||
def test_clamp_banking_min(banking_source, golden) -> None: | ||
current_balance = banking_source.col("current_balance") | ||
min_balance = banking_source.col("min_balance") | ||
golden.jsonl( | ||
kd.record( | ||
{ | ||
"current_balance": current_balance, | ||
"clamped_balance": current_balance.clamp(min=min_balance), | ||
} | ||
) | ||
) | ||
|
||
|
||
def test_clamp_banking_max(banking_source, golden) -> None: | ||
current_balance = banking_source.col("current_balance") | ||
max_balance = banking_source.col("max_balance") | ||
golden.jsonl( | ||
kd.record( | ||
{ | ||
"current_balance": current_balance, | ||
"clamped_balance": current_balance.clamp(max=max_balance), | ||
} | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import kaskada as kd | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def source() -> kd.sources.CsvString: | ||
content = "\n".join( | ||
[ | ||
"time,key,m,n,o", | ||
"1996-12-19T16:39:57,A,5,10,15", | ||
"1996-12-19T16:39:58,B,24,3,15", | ||
"1996-12-19T16:39:59,A,17,6,15", | ||
"1996-12-19T16:40:00,A,,9,15", | ||
"1996-12-19T16:40:01,A,12,,15", | ||
"1996-12-19T16:40:02,A,,,15", | ||
] | ||
) | ||
return kd.sources.CsvString(content, time_column_name="time", key_column_name="key") | ||
|
||
|
||
def test_coalesce(source, golden) -> None: | ||
m = source.col("m") | ||
n = source.col("n") | ||
golden.jsonl(kd.record({"m": m, "n": n, "coalesced_val": m.coalesce(n)})) | ||
|
||
|
||
def test_coalesce_three(source, golden) -> None: | ||
m = source.col("m") | ||
n = source.col("n") | ||
o = source.col("o") | ||
golden.jsonl(kd.record({"m": m, "n": n, "o": o, "coalesced_val": m.coalesce(n, o)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import kaskada as kd | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def source() -> kd.sources.CsvString: | ||
content = "\n".join( | ||
[ | ||
"time,key,m", | ||
"1996-12-19T16:39:57,A,1", | ||
"1996-12-19T16:39:58,B,1", | ||
"1996-12-19T16:39:59,A,2", | ||
"1996-12-19T16:40:00,A,3", | ||
"1996-12-19T16:40:01,A,4", | ||
"1996-12-19T16:40:02,A,5", | ||
] | ||
) | ||
return kd.sources.CsvString(content, time_column_name="time", key_column_name="key") | ||
|
||
|
||
def test_exp(source, golden) -> None: | ||
m = source.col("m") | ||
golden.jsonl(kd.record({"m": m, "exp_m": m.exp()})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import kaskada as kd | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def source() -> kd.sources.CsvString: | ||
content = "\n".join( | ||
[ | ||
"time,key,m", | ||
"1996-12-19T16:39:57,A,5", | ||
"1996-12-19T16:39:58,B,100.0001", | ||
"1996-12-19T16:39:59,A,2.50", | ||
"1996-12-19T16:40:00,A,", | ||
"1996-12-19T16:40:01,A,0.99", | ||
"1996-12-19T16:40:02,A,1.01", | ||
] | ||
) | ||
return kd.sources.CsvString(content, time_column_name="time", key_column_name="key") | ||
|
||
|
||
def test_floor(source, golden) -> None: | ||
m = source.col("m") | ||
golden.jsonl(kd.record({"m": m, "floor_m": m.floor()})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_key":"A","m":5.0,"ceil_m":5.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_key":"B","m":100.0001,"ceil_m":101.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_key":"A","m":2.5,"ceil_m":3.0} | ||
{"_time":"1996-12-19T16:40:00.000000000","_key":"A","m":null,"ceil_m":null} | ||
{"_time":"1996-12-19T16:40:01.000000000","_key":"A","m":0.99,"ceil_m":1.0} | ||
{"_time":"1996-12-19T16:40:02.000000000","_key":"A","m":1.01,"ceil_m":2.0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_subsort":0,"_key_hash":12960666915911099378,"_key":"A","m":5.0,"ceil_m":5.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_subsort":1,"_key_hash":2867199309159137213,"_key":"B","m":100.0001,"ceil_m":101.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_subsort":2,"_key_hash":12960666915911099378,"_key":"A","m":2.5,"ceil_m":3.0} | ||
{"_time":"1996-12-19T16:40:00.000000000","_subsort":3,"_key_hash":12960666915911099378,"_key":"A","m":null,"ceil_m":null} | ||
{"_time":"1996-12-19T16:40:01.000000000","_subsort":4,"_key_hash":12960666915911099378,"_key":"A","m":0.99,"ceil_m":1.0} | ||
{"_time":"1996-12-19T16:40:02.000000000","_subsort":5,"_key_hash":12960666915911099378,"_key":"A","m":1.01,"ceil_m":2.0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_subsort":0,"_key_hash":12960666915911099378,"_key":"A","m":5.0,"clamped_m":5.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_subsort":1,"_key_hash":2867199309159137213,"_key":"B","m":100.0001,"clamped_m":100.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_subsort":2,"_key_hash":12960666915911099378,"_key":"A","m":2.5,"clamped_m":5.0} | ||
{"_time":"1996-12-19T16:40:00.000000000","_subsort":3,"_key_hash":12960666915911099378,"_key":"A","m":null,"clamped_m":null} | ||
{"_time":"1996-12-19T16:40:01.000000000","_subsort":4,"_key_hash":12960666915911099378,"_key":"A","m":0.99,"clamped_m":5.0} | ||
{"_time":"1996-12-19T16:40:02.000000000","_subsort":5,"_key_hash":12960666915911099378,"_key":"A","m":1.01,"clamped_m":5.0} |
6 changes: 6 additions & 0 deletions
6
python/pytests/golden/clamp_test/test_clamp_banking_max.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_key":"A","current_balance":5.0,"clamped_balance":5.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_key":"B","current_balance":6.0,"clamped_balance":6.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_key":"A","current_balance":7.0,"clamped_balance":7.0} | ||
{"_time":"1996-12-19T16:40:00.000000000","_key":"A","current_balance":8.0,"clamped_balance":8.0} | ||
{"_time":"1996-12-19T16:40:01.000000000","_key":"A","current_balance":9.0,"clamped_balance":9.0} | ||
{"_time":"1996-12-19T16:40:02.000000000","_key":"A","current_balance":10.0,"clamped_balance":10.0} |
6 changes: 6 additions & 0 deletions
6
python/pytests/golden/clamp_test/test_clamp_banking_min.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_key":"A","current_balance":5.0,"clamped_balance":6.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_key":"B","current_balance":6.0,"clamped_balance":7.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_key":"A","current_balance":7.0,"clamped_balance":8.0} | ||
{"_time":"1996-12-19T16:40:00.000000000","_key":"A","current_balance":8.0,"clamped_balance":9.0} | ||
{"_time":"1996-12-19T16:40:01.000000000","_key":"A","current_balance":9.0,"clamped_balance":10.0} | ||
{"_time":"1996-12-19T16:40:02.000000000","_key":"A","current_balance":10.0,"clamped_balance":11.0} |
6 changes: 6 additions & 0 deletions
6
python/pytests/golden/clamp_test/test_clamp_banking_min_max.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_key":"A","current_balance":5.0,"clamped_balance":6.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_key":"B","current_balance":6.0,"clamped_balance":7.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_key":"A","current_balance":7.0,"clamped_balance":8.0} | ||
{"_time":"1996-12-19T16:40:00.000000000","_key":"A","current_balance":8.0,"clamped_balance":9.0} | ||
{"_time":"1996-12-19T16:40:01.000000000","_key":"A","current_balance":9.0,"clamped_balance":10.0} | ||
{"_time":"1996-12-19T16:40:02.000000000","_key":"A","current_balance":10.0,"clamped_balance":11.0} |
6 changes: 6 additions & 0 deletions
6
python/pytests/golden/clamp_test/test_clamp_banknig_min_max.jsonl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_subsort":0,"_key_hash":12960666915911099378,"_key":"A","current_balance":5.0,"clamped_balance":6.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_subsort":1,"_key_hash":2867199309159137213,"_key":"B","current_balance":6.0,"clamped_balance":7.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_subsort":2,"_key_hash":12960666915911099378,"_key":"A","current_balance":7.0,"clamped_balance":8.0} | ||
{"_time":"1996-12-19T16:40:00.000000000","_subsort":3,"_key_hash":12960666915911099378,"_key":"A","current_balance":8.0,"clamped_balance":9.0} | ||
{"_time":"1996-12-19T16:40:01.000000000","_subsort":4,"_key_hash":12960666915911099378,"_key":"A","current_balance":9.0,"clamped_balance":10.0} | ||
{"_time":"1996-12-19T16:40:02.000000000","_subsort":5,"_key_hash":12960666915911099378,"_key":"A","current_balance":10.0,"clamped_balance":11.0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"_time":"1996-12-19T16:39:57.000000000","_key":"A","m":5.0,"clamped_min":5.0} | ||
{"_time":"1996-12-19T16:39:58.000000000","_key":"B","m":100.0001,"clamped_min":100.0} | ||
{"_time":"1996-12-19T16:39:59.000000000","_key":"A","m":2.5,"clamped_min":2.5} | ||
{"_time":"1996-12-19T16:40:00.000000000","_key":"A","m":null,"clamped_min":null} | ||
{"_time":"1996-12-19T16:40:01.000000000","_key":"A","m":0.99,"clamped_min":0.99} | ||
{"_time":"1996-12-19T16:40:02.000000000","_key":"A","m":1.01,"clamped_min":1.01} |
Oops, something went wrong.