-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathtest_polars.py
More file actions
39 lines (31 loc) · 1.41 KB
/
test_polars.py
File metadata and controls
39 lines (31 loc) · 1.41 KB
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
37
38
39
from unittest import TestCase
from polars import DataFrame
from pandas import Timestamp
from investing_algorithm_framework import convert_polars_to_pandas
class TestConvertPandasToPolars(TestCase):
def test_convert_pandas_to_polars(self):
polars_df = DataFrame({
"Datetime": ["2021-01-01", "2021-01-02", "2021-01-03"],
"Close": [1, 2, 3]
})
polars_df_converted = convert_polars_to_pandas(polars_df, add_index=False)
self.assertEqual(polars_df_converted.shape, (3, 2))
# Check if the columns are as expected
column_names = polars_df_converted.columns.tolist()
self.assertEqual(set(column_names), {'Close', 'Datetime'})
# Check if the index is a datetime object
self.assertEqual(
polars_df_converted['Datetime'][0], Timestamp('2021-01-01 00:00:00')
)
polars_df_converted = convert_polars_to_pandas(
polars_df, add_index=True
)
self.assertEqual(polars_df_converted.shape, (3, 1))
# Check if the columns are as expected
column_names = polars_df_converted.columns.tolist()
self.assertEqual(set(column_names), {'Close'})
# Check if the index is a datetime object
self.assertEqual(polars_df_converted.index.dtype, "datetime64[us]")
self.assertEqual(
polars_df_converted.index[0], Timestamp('2021-01-01 00:00:00')
)