def filter_col_name_by_dtypes(df, data_type): """ Return column names filtered by the column data type :param df: Dataframe which columns are going to be filtered :param data_type: Datatype used to filter the column. :type data_type: str or list :return: """ data_type = parse_spark_dtypes(data_type) # isinstace require a tuple data_type = tuple(val_to_list(data_type)) # Filter columns by data type return [c for c in df.columns if isinstance(df.schema[c].dataType, data_type)]
def is_column_a(df, column, dtypes): """ Check if column match a list of data types :param df: :param column: :param dtypes: :return: """ data_type = tuple(val_to_list(parse_spark_dtypes(dtypes))) column = one_list_to_val(column) # Filter columns by data type return isinstance(df.schema[column].dataType, data_type)
def is_column_a(df, column, dtypes): """ Check if column match a list of data types :param df: dataframe :param column: column to be compared with :param dtypes: types to be checked :return: """ column = val_to_list(column) if len(column) > 1: RaiseIt.length_error(column, 1) data_type = tuple(val_to_list(parse_spark_dtypes(dtypes))) column = one_list_to_val(column) # Filter columns by data type return isinstance(df.schema[column].dataType, data_type)