I implemented the following design using abstract class and its subclass class as follows
from abc import ABC, abstractmethod
class Pipeline(ABC):
@abstractmethod
def read_data(self):
pass
def __init__(self, **kwargs):
self.raw_data = self.read_data()
self.process_data = self.raw_data[self.used_cols]
class case1(Pipeline):
def read_data(self):
return pd.read_csv("file location") # just hard coding for the file location
@property
def used_cols(self):
return ['col_1', 'col_2','col_3','col_4']
I can invoke the class of case1 as follows. It will in fact read a csv file into pandas dataframe.
data = case1()
This existing design will return four hard coded columns, e.g., 'col_1','col_2','col_3' and 'col_4', and it just works fine. At present, I would like to control the columns to be returned by modifying the subclass, in specific, the function of used_cols. I modified class case1 as follows, but it will cause the error message.
class case1(Pipeline):
def read_data(self):
return pd.read_csv("file location") # just hard coding for the file location
@property
def used_cols(self, selected_cols):
return selectd_cols
It was called as follows
selected_cols = ['col_2','col_3']
data = case1(selected_cols)
It turns out that this modification is not right, and generates the error message such as TypeError: init_subclass() takes no keyword arguments So my question is how to modify the subclass to get the desired control.