Allow single string input for time columns

This commit is contained in:
Christophe Bedard 2019-11-10 16:05:23 -08:00
parent 7652873666
commit 53b7da5c75

View file

@ -53,19 +53,24 @@ class DataModelUtil():
@staticmethod @staticmethod
def convert_time_columns( def convert_time_columns(
original: DataFrame, original: DataFrame,
columns_ns_to_ms: List[str] = [], columns_ns_to_ms: Union[List[str], str] = [],
columns_ns_to_datetime: List[str] = [], columns_ns_to_datetime: Union[List[str], str] = [],
inplace: bool = True, inplace: bool = True,
) -> DataFrame: ) -> DataFrame:
""" """
Convert time columns from nanoseconds to either milliseconds or `datetime` objects. Convert time columns from nanoseconds to either milliseconds or `datetime` objects.
:param original: the original `DataFrame` :param original: the original `DataFrame`
:param columns_ns_to_ms: the columns for which to convert ns to ms :param columns_ns_to_ms: the column(s) for which to convert ns to ms
:param columns_ns_to_datetime: the columns for which to convert ns to `datetime` :param columns_ns_to_datetime: the column(s) for which to convert ns to `datetime`
:param inplace: whether to convert in place or to return a copy :param inplace: whether to convert in place or to return a copy
:return: the resulting `DataFrame` :return: the resulting `DataFrame`
""" """
if not isinstance(columns_ns_to_ms, list):
columns_ns_to_ms = list(columns_ns_to_ms)
if not isinstance(columns_ns_to_datetime, list):
columns_ns_to_datetime = list(columns_ns_to_datetime)
df = original if inplace else original.copy() df = original if inplace else original.copy()
# Convert from ns to ms # Convert from ns to ms
if len(columns_ns_to_ms) > 0: if len(columns_ns_to_ms) > 0: