Programming Language/Python
TypeError: dict_to_df() takes 1 positional argument but 2 were given 클래스 함수에서 발생한 에러
draidev
2024. 1. 25. 16:10
- 아래와 같이 model.py 모듈에서 Model 클래스 안의 함수 inference_malware_file() 함수에서 dict_to_df() 를 호출하는데 위와 같은 에러 메시지 발생
- Class안의 함수인데 self 값을 주지 않아서 생긴 에러였다.
class Model:
def __init__(self, model_type='random_forest'):
self.model = None
self.model_type = None
self.features = None
if model_type == 'random_forest':
self.model = RandomForestClassifier()
self.model_type = 'random_forest'
...
def inference_malware_file(self, file_path):
if file_path == []:
new_df = pd.DataFrame()
for f in file_path:
data = extract_infos(file_path)
data_df = self.dict_to_df(data)
new_df = pd.concat([new_df, data_df], axis=1)
return self.model.predict(new_df)
else:
data = extract_infos(file_path)
print(data,'\n', type(data))
data_df = self.dict_to_df(data)
return self.model.predict(data_df)
def dict_to_df(self, dict_data):
return pd.DataFrame.from_dict(dict_data, orient='index').T