-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_polars.py
More file actions
36 lines (29 loc) · 807 Bytes
/
test_polars.py
File metadata and controls
36 lines (29 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import ast
import random
import unittest
import polars as pl
from polars.testing import assert_frame_equal
from .mock_user import UserQuery
class PolarsTests(unittest.TestCase):
def setUp(self):
random.seed(100)
self.maxDiff = None
def test_project(self):
df = (
UserQuery(range(1, 10))
.project([":id", "name", "age"])
.where(ast.Expr("user.age >= 16"))
.order_by(ast.Expr("user.age"))
.take(3)
.to_polars()
)
expected = pl.DataFrame(
{
":id": [1, 4, 2],
"name": ["id1", "id4", "id2"],
"age": [16, 16, 17],
}
)
assert_frame_equal(expected, df)
if __name__ == "__main__":
unittest.main()