# Built-in modules
import re
# Hand-made modules
from .base import DataFrameHandlerBase

REGEX_DROP_LABEL_NAME_PREFIXES = {
    "max_ws_",
    "ave_wv_",
    "ave_ws_",
    "max_tp_",
    "min_tp_",
    "sl_",
    "sd_",
    "vb_",
    "weather_",
    "dsr_",
    "dsd_",
    "dsr_"
}
DROP_LABEL_NAMES = [
    "weather",
    "weather_detail",
    "wind",
    "wave"
]
REGEX_SHIFT_COL_NAME_PREFIXES = [
    "pr_*",
    "max_iws_*",
    "gsr_*",
    "lap_*",
    "sap_*",
    "cap_*",
    "3h_cap_*",
    "rhm_*",
    "min_rhm_*",
    "vp_*",
    "dtp_*",
]


class TimeSeriesReshaper(DataFrameHandlerBase):
    def __init__(self):
        super().__init__()
        self.REGEX_DROP_LABEL_NAME_PREFIXES = REGEX_DROP_LABEL_NAME_PREFIXES
        self.DROP_LABEL_NAMES = DROP_LABEL_NAMES
        self.REGEX_SHIFT_COL_NAME_PREFIXES = REGEX_SHIFT_COL_NAME_PREFIXES

    def shift_indexes(self, df, freq, shift_col_name_list):
        non_shift_col_name_list = [
            col_name for col_name in df.columns \
            if col_name not in shift_col_name_list
        ]

        df_shifted = df[shift_col_name_list].shift(freq=freq, axis=0)
        df_non_shifted = df[non_shift_col_name_list]

        return df_non_shifted.merge(df_shifted, **self.KWARGS_OUTER_MERGE)

    @staticmethod
    def get_regex_matched_col_name(col_name_list, regex_name_prefix_list):
        return [
            col_name \
            for col_name in col_name_list \
            for name_prefix in regex_name_prefix_list \
            if re.compile("^" + name_prefix + ".*$").match(col_name)
        ]

    @staticmethod
    def drop_columns_of_many_nan(df, nan_number_threshold):
        reserve_column_list = [
            v < nan_number_threshold for v in df.isnull().sum(axis=0)
        ]

        return df.loc[:, reserve_column_list]


if __name__ == '__main__':
    print("time series !")

@@ -81,17 +81,16 @@
 lerBase%0A
-%0A
 REGEX_DR
@@ -118,170 +118,26 @@
 S = 
-%7B%0A    %22max_ws_%22,%0A    %22ave_wv_%22,%0A    %22ave_ws_%22,%0A    %22max_tp_%22,%0A    %22min_tp_%22,%0A    %22sl_%22,%0A    %22sd_%22,%0A    %22vb_%22,%0A    %22weather_%22,%0A    %22dsr_%22,%0A    %22dsd_%22,%0A    %22dsr_%22%0A%7D
+%5B%0A    %22weather_%22%0A%5D
 %0ADRO
@@ -258,17 +258,16 @@
     %22pr_
-*
 %22,%0A    %22
@@ -278,22 +278,126 @@
 iws_
-*%22,%0A    %22gsr_*
+%22,%0A    %22ave_wv_%22,%0A    %22ave_ws_%22,%0A    %22max_tp_%22,%0A    %22min_tp_%22,%0A    %22sl_%22,%0A    %22dsr_%22,%0A    %22gsr_%22,%0A    %22sd_%22,%0A    %22dsd_
 %22,%0A 
@@ -404,17 +404,16 @@
    %22lap_
-*
 %22,%0A    %22
@@ -416,17 +416,16 @@
    %22sap_
-*
 %22,%0A    %22
@@ -424,25 +424,24 @@
 %22,%0A    %22cap_
-*
 %22,%0A    %223h_c
@@ -443,17 +443,16 @@
 %223h_cap_
-*
 %22,%0A    %22
@@ -451,25 +451,24 @@
 %22,%0A    %22rhm_
-*
 %22,%0A    %22min_
@@ -471,17 +471,16 @@
 min_rhm_
-*
 %22,%0A    %22
@@ -482,17 +482,16 @@
     %22vp_
-*
 %22,%0A    %22
@@ -494,17 +494,16 @@
    %22dtp_
-*
 %22,%0A%5D%0A%0A%0Ac

Modify drop/shift labels