|
1 | 1 | import os
|
2 | 2 |
|
| 3 | +import numpy as np |
| 4 | +import pandas as pd |
3 | 5 | import pytest
|
4 | 6 | from visions.test.series import get_series
|
5 | 7 | from visions.test.utils import (
|
|
14 | 16 | from tests.unit.test_utils import patch_arg
|
15 | 17 | from ydata_profiling.config import Settings
|
16 | 18 | from ydata_profiling.model.typeset import ProfilingTypeSet
|
| 19 | +from ydata_profiling.profile_report import ProfileReport |
17 | 20 |
|
18 | 21 | base_path = os.path.abspath(os.path.dirname(__file__))
|
19 | 22 |
|
|
161 | 164 | )
|
162 | 165 | )
|
163 | 166 | def test_contains(name, series, contains_type, member):
|
164 |
| - """Test the generated combinations for "series in type" |
| 167 | + """Test the generated combinations for "series in type". |
165 | 168 |
|
166 | 169 | Args:
|
167 | 170 | series: the series to test
|
@@ -349,3 +352,35 @@ def test_conversion(name, source_type, relation_type, series, member):
|
349 | 352 | """
|
350 | 353 | result, message = convert(name, source_type, relation_type, series, member)
|
351 | 354 | assert result, message
|
| 355 | + |
| 356 | + |
| 357 | +@pytest.fixture |
| 358 | +def dataframe(size: int = 1000) -> pd.DataFrame: |
| 359 | + return pd.DataFrame( |
| 360 | + { |
| 361 | + "boolean": np.random.choice([True, False], size=size), |
| 362 | + "numeric": np.random.rand(size), |
| 363 | + "categorical": np.random.choice(np.arange(5), size=size), |
| 364 | + "timeseries": np.arange(size), |
| 365 | + } |
| 366 | + ) |
| 367 | + |
| 368 | + |
| 369 | +def convertion_map() -> list: |
| 370 | + types = { |
| 371 | + "boolean": ["Categorical", "Unsupported"], |
| 372 | + "numeric": ["Categorical", "Boolean", "Unsupported"], |
| 373 | + "categorical": ["Numeric", "Boolean", "TimeSeries", "Unsupported"], |
| 374 | + "timeseries": ["Numeric", "Boolean", "Categorical", "Unsupported"], |
| 375 | + } |
| 376 | + return [(k, {k: i}) for k, v in types.items() for i in v] |
| 377 | + |
| 378 | + |
| 379 | +@pytest.mark.parametrize("column,type_schema", convertion_map()) |
| 380 | +def test_type_schema(dataframe: pd.DataFrame, column: str, type_schema: dict): |
| 381 | + prof = ProfileReport(dataframe[[column]], tsmode=True, type_schema=type_schema) |
| 382 | + prof.get_description() |
| 383 | + assert isinstance(prof.typeset, ProfilingTypeSet) |
| 384 | + assert prof.typeset.type_schema[column] == prof.typeset._get_type( |
| 385 | + type_schema[column] |
| 386 | + ) |
0 commit comments