added more tests
This commit is contained in:
parent
9ddf70fc61
commit
b4d5291572
@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 2,
|
||||||
"id": "3f7938c0-98e3-43b8-86e8-4f000cda7ce5",
|
"id": "3f7938c0-98e3-43b8-86e8-4f000cda7ce5",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -16,7 +16,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 3,
|
||||||
"id": "4b8ccd5f-dfff-4202-82c4-f66a30c122b6",
|
"id": "4b8ccd5f-dfff-4202-82c4-f66a30c122b6",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -27,7 +27,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 12,
|
||||||
"id": "c52b0c2c-dd01-48dd-9ffa-3147ec9571ef",
|
"id": "c52b0c2c-dd01-48dd-9ffa-3147ec9571ef",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -50,7 +50,7 @@
|
|||||||
"\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')"
|
"\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 3,
|
"execution_count": 12,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 6,
|
||||||
"id": "9e8ff6c6-3a36-435a-ba87-5b9844c18779",
|
"id": "9e8ff6c6-3a36-435a-ba87-5b9844c18779",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -73,7 +73,7 @@
|
|||||||
" (datetime.datetime(2021, 5, 31, 0, 0), 74.85)]"
|
" (datetime.datetime(2021, 5, 31, 0, 0), 74.85)]"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 4,
|
"execution_count": 6,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 16,
|
"execution_count": 8,
|
||||||
"id": "086d4377-d1b1-4e51-84c0-39dee28ef75e",
|
"id": "086d4377-d1b1-4e51-84c0-39dee28ef75e",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -100,7 +100,7 @@
|
|||||||
"\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')"
|
"\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 16,
|
"execution_count": 8,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 9,
|
||||||
"id": "6f1226a3-2327-435b-88e7-fd0fdcc8cc1c",
|
"id": "6f1226a3-2327-435b-88e7-fd0fdcc8cc1c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -127,7 +127,7 @@
|
|||||||
"\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')"
|
"\t (datetime.datetime(2022, 2, 14, 0, 0), 82.53299999999999)], frequency='D')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 5,
|
"execution_count": 9,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": 10,
|
||||||
"id": "e815edc9-3746-4192-814e-bd27b2771a0c",
|
"id": "e815edc9-3746-4192-814e-bd27b2771a0c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -158,7 +158,7 @@
|
|||||||
" (datetime.datetime(2013, 1, 15, 0, 0), 19.272000000000002)]"
|
" (datetime.datetime(2013, 1, 15, 0, 0), 19.272000000000002)]"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 9,
|
"execution_count": 10,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 11,
|
||||||
"id": "dc469722-c816-4b57-8d91-7a3b865f86be",
|
"id": "dc469722-c816-4b57-8d91-7a3b865f86be",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"tags": []
|
"tags": []
|
||||||
@ -180,7 +180,7 @@
|
|||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"CPU times: total: 15.6 ms\n",
|
"CPU times: total: 15.6 ms\n",
|
||||||
"Wall time: 14 ms\n"
|
"Wall time: 10 ms\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -4,7 +4,7 @@ import random
|
|||||||
from typing import Literal, Sequence
|
from typing import Literal, Sequence
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from fincal.core import Frequency
|
from fincal.core import AllFrequencies, Frequency, Series
|
||||||
from fincal.fincal import TimeSeries, create_date_series
|
from fincal.fincal import TimeSeries, create_date_series
|
||||||
|
|
||||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -53,6 +53,40 @@ def create_test_data(
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class TestFrequency:
|
||||||
|
def test_creation(self):
|
||||||
|
D = Frequency('daily', 'days', 1, 1, 'D')
|
||||||
|
assert D.days == 1
|
||||||
|
assert D.symbol == 'D'
|
||||||
|
assert D.name == 'daily'
|
||||||
|
assert D.value == 1
|
||||||
|
assert D.freq_type == 'days'
|
||||||
|
|
||||||
|
|
||||||
|
class TestAllFrequencies:
|
||||||
|
def test_attributes(self):
|
||||||
|
assert hasattr(AllFrequencies, 'D')
|
||||||
|
assert hasattr(AllFrequencies, 'M')
|
||||||
|
assert hasattr(AllFrequencies, 'Q')
|
||||||
|
|
||||||
|
def test_days(self):
|
||||||
|
assert AllFrequencies.D.days == 1
|
||||||
|
assert AllFrequencies.M.days == 30
|
||||||
|
assert AllFrequencies.Q.days == 91
|
||||||
|
|
||||||
|
def test_symbol(self):
|
||||||
|
assert AllFrequencies.H.symbol == 'H'
|
||||||
|
assert AllFrequencies.W.symbol == 'W'
|
||||||
|
|
||||||
|
def test_values(self):
|
||||||
|
assert AllFrequencies.H.value == 6
|
||||||
|
assert AllFrequencies.Y.value == 1
|
||||||
|
|
||||||
|
def test_type(self):
|
||||||
|
assert AllFrequencies.Q.freq_type == 'months'
|
||||||
|
assert AllFrequencies.W.freq_type == 'days'
|
||||||
|
|
||||||
|
|
||||||
class TestDateSeries:
|
class TestDateSeries:
|
||||||
def test_daily(self):
|
def test_daily(self):
|
||||||
start_date = datetime.datetime(2020, 1, 1)
|
start_date = datetime.datetime(2020, 1, 1)
|
||||||
@ -134,18 +168,28 @@ class TestFincal:
|
|||||||
data = create_test_data(frequency='D', eomonth=False, n=500, gaps=0.1, month_position='start', date_as_str=True)
|
data = create_test_data(frequency='D', eomonth=False, n=500, gaps=0.1, month_position='start', date_as_str=True)
|
||||||
time_series = TimeSeries(data, frequency="D")
|
time_series = TimeSeries(data, frequency="D")
|
||||||
ffill_data = time_series.ffill()
|
ffill_data = time_series.ffill()
|
||||||
assert len(ffill_data) > 498
|
assert len(ffill_data) >= 498
|
||||||
|
|
||||||
ffill_data = time_series.ffill(inplace=True)
|
ffill_data = time_series.ffill(inplace=True)
|
||||||
assert ffill_data is None
|
assert ffill_data is None
|
||||||
assert len(time_series) > 498
|
assert len(time_series) >= 498
|
||||||
|
|
||||||
def test_slicing(self):
|
def test_iloc_slicing(self):
|
||||||
data = create_test_data(frequency='D', eomonth=False, n=50, gaps=0, month_position='start', date_as_str=True)
|
data = create_test_data(frequency='D', eomonth=False, n=50, gaps=0, month_position='start', date_as_str=True)
|
||||||
time_series = TimeSeries(data, frequency="D")
|
time_series = TimeSeries(data, frequency="D")
|
||||||
assert time_series[0] is not None
|
assert time_series.iloc[0] is not None
|
||||||
assert time_series[:3] is not None
|
assert time_series.iloc[:3] is not None
|
||||||
assert time_series[5:7] is not None
|
assert time_series.iloc[5:7] is not None
|
||||||
assert isinstance(time_series[0], tuple)
|
assert isinstance(time_series.iloc[0], tuple)
|
||||||
assert isinstance(time_series[10:20], list)
|
assert isinstance(time_series.iloc[10:20], list)
|
||||||
assert len(time_series[10:20]) == 10
|
assert len(time_series.iloc[10:20]) == 10
|
||||||
|
|
||||||
|
def test_key_slicing(self):
|
||||||
|
data = create_test_data(frequency='D', eomonth=False, n=50, gaps=0, month_position='start', date_as_str=True)
|
||||||
|
time_series = TimeSeries(data, frequency="D")
|
||||||
|
available_date = time_series.iloc[5][0]
|
||||||
|
assert time_series[available_date] is not None
|
||||||
|
assert isinstance(time_series['dates'], Series)
|
||||||
|
assert isinstance(time_series['values'], Series)
|
||||||
|
assert len(time_series.dates) == 50
|
||||||
|
assert len(time_series.values) == 50
|
||||||
|
Loading…
Reference in New Issue
Block a user