Skip to content

Commit

Permalink
feat!: Remove parameter string_representation from infer_data_type.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mbelak-dtml committed Aug 31, 2023
1 parent 131f18c commit 02a5fe7
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions edvart/data_types.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,38 +21,36 @@ 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:
Expand Down

0 comments on commit 02a5fe7

Please sign in to comment.