Skip to content

Commit

Permalink
add tests for defining index
Browse files Browse the repository at this point in the history
  • Loading branch information
MorrisNein committed Jan 30, 2023
1 parent d1747f5 commit f489698
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/data/dummy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a,b,c
1,4,7
2,5,8
3,6,9
37 changes: 36 additions & 1 deletion test/unit/data/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from sklearn.datasets import load_iris

from fedot.core.data.data import InputData
from fedot.core.data.data import InputData, get_df_from_csv
from fedot.core.pipelines.node import PrimaryNode
from fedot.core.pipelines.pipeline import Pipeline
from fedot.core.repository.dataset_types import DataTypesEnum
Expand Down Expand Up @@ -207,3 +207,38 @@ def test_data_convert_dt_indexes_correct():
assert np.all(train_data.supplementary_data.non_int_idx == old_train_data_idx)
assert np.all(train_pred_data.supplementary_data.non_int_idx == old_train_pred_data_idx)
assert np.all(test_data.supplementary_data.non_int_idx == old_test_data_idx)


@pytest.mark.parametrize('columns_to_use, possible_idx_keywords',
[
(None, ['b', 'c', 'a', 'some']),
(['b', 'c'], ['a', 'some'])
])
def test_define_index_from_csv_with_first_index_column(columns_to_use, possible_idx_keywords):
dummy_csv_path = fedot_project_root().joinpath('test/data/dummy.csv')
df = get_df_from_csv(dummy_csv_path, delimiter=',',
columns_to_use=columns_to_use, possible_idx_keywords=possible_idx_keywords)
assert df.index.name == 'a'
assert np.array_equal(df.index, [1, 2, 3])
assert np.array_equal(df.columns, ['b', 'c'])
assert np.array_equal(df, list(zip([4, 5, 6], [7, 8, 9])))


def test_define_index_from_csv_with_non_first_index_column():
dummy_csv_path = fedot_project_root().joinpath('test/data/dummy.csv')
df = get_df_from_csv(dummy_csv_path, delimiter=',', columns_to_use=['b', 'c'],
possible_idx_keywords=['a', 'b', 'c', 'some'])
assert df.index.name == 'b'
assert np.array_equal(df.index, [4, 5, 6])
assert np.array_equal(df.columns, ['c'])
assert np.array_equal(df, [[7], [8], [9]])


def test_define_index_from_csv_without_index_column():
dummy_csv_path = fedot_project_root().joinpath('test/data/dummy.csv')
df = get_df_from_csv(dummy_csv_path, delimiter=',',
possible_idx_keywords=['some'])
assert df.index.name is None
assert np.array_equal(df.index, [0, 1, 2])
assert np.array_equal(df.columns, ['a', 'b', 'c'])
assert np.array_equal(df, list(zip([1, 2, 3], [4, 5, 6], [7, 8, 9])))

0 comments on commit f489698

Please sign in to comment.