From 98632ae4b65a7d00d77350a407f8a631f6dfe85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bel=C3=A1k?= Date: Thu, 31 Aug 2023 14:12:54 +0200 Subject: [PATCH] feat!: Remove parameter `string_representation` from `infer_data_type`. The parameter is no longer used by in `edvart`. BREAKING CHANGE: Parameter `string_representation` of `edvart.data_types.infer_data_type` removed. Call `str` on the result instead to get the string representation. --- edvart/data_types.py | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/edvart/data_types.py b/edvart/data_types.py index 406e9b8..c8829af 100644 --- a/edvart/data_types.py +++ b/edvart/data_types.py @@ -1,7 +1,6 @@ """Module defines data types and helper function for recognizing them.""" from enum import IntEnum -from typing import Union import numpy as np import pandas as pd @@ -21,39 +20,36 @@ class DataType(IntEnum): def __str__(self): return self.name.lower() - -def infer_data_type(series: pd.Series, string_representation: bool = False) -> Union[DataType, str]: +# pylint: disable=too-many-return-statements +def infer_data_type(series: pd.Series) -> DataType: """Infers the data type of the series passed in. Parameters ---------- series : pd.Series Series from which to infer data type. - string_representation : bool - Whether to return the resulting data type as DataType enum value or string. Returns ------- - DataType : Union[DataType, str] - Inferred custom edvart data type or its string representation. + DataType + Inferred custom edvart data type. """ - ret = None + if series.empty: + return DataType.UNKNOWN if is_missing(series): - ret = DataType.MISSING + return DataType.MISSING if is_boolean(series): - ret = DataType.BOOLEAN - elif is_date(series): - ret = DataType.DATE - elif is_unique(series): - ret = DataType.UNIQUE - elif is_categorical(series): - ret = DataType.CATEGORICAL - elif is_numeric(series): - ret = DataType.NUMERIC - else: - ret = DataType.UNKNOWN - - return str(ret) if string_representation else ret + return DataType.BOOLEAN + if is_date(series): + return DataType.DATE + if is_unique(series): + return DataType.UNIQUE + if is_categorical(series): + return DataType.CATEGORICAL + if is_numeric(series): + return DataType.NUMERIC + + return DataType.UNKNOWN def is_unique(series: pd.Series) -> bool: