-
Notifications
You must be signed in to change notification settings - Fork 60
Refactor election expenses classifier #89
Changes from 13 commits
e47610b
993bab4
ee324e9
e572e9b
afce56e
8fa947e
4ea4974
d906fe7
250022a
6025ef5
d63ba5d
e9c3ac8
1fc676f
a3bd233
8b14e51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,18 +9,28 @@ | |
class TestElectionExpensesClassifier(TestCase): | ||
|
||
def setUp(self): | ||
self.dataset = pd.read_csv('rosie/chamber_of_deputies/tests/fixtures/election_expenses_classifier.csv', | ||
dtype={'name': np.str, 'legal_entity': np.str}) | ||
self.subject = ElectionExpensesClassifier() | ||
self.election_expenser_classifier = ElectionExpensesClassifier() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering: as each test file refers to only one classifier I wouldn't bother shortening it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I aiming to achieve people that have no context of a classifier, to understand what is this referencing to. How do you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hopefully readers know which file they are reading… or maybe I'm just too optimistic. But nothing against There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that way, I'm with @cuducos, I prefer something meaningful but simple at the same way :) |
||
|
||
def test_is_election_company(self): | ||
self.assertEqual(self.subject.predict(self.dataset)[0], True) | ||
def test_legal_entity_is_a_election_company(self): | ||
self.dataframe = self._create_dataframe([['CARLOS ALBERTO DA SILVA', 'ELEICAO 2006 CARLOS ALBERTO DA SILVA DEPUTADO', '409-0 - CANDIDATO A CARGO POLITICO ELETIVO']]) | ||
|
||
def test_is_not_election_company(self): | ||
self.assertEqual(self.subject.predict(self.dataset)[1], False) | ||
prediction_result = self.election_expenser_classifier.predict(self.dataframe) | ||
|
||
def test_fit(self): | ||
self.assertEqual(self.subject.fit(self.dataset), self.subject) | ||
self.assertEqual(prediction_result[0], True) | ||
|
||
def test_tranform(self): | ||
self.assertEqual(self.subject.transform(), self.subject) | ||
def test_legal_entity_is_not_election_company(self): | ||
self.dataframe = self._create_dataframe([['PAULO ROGERIO ROSSETO DE MELO', 'POSTO ROTA 116 DERIVADOS DE PETROLEO LTDA', '401-4 - EMPRESA INDIVIDUAL IMOBILIARIA']]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about making this test a bit more readable? def test_legal_entity_is_not_election_company(self):
data = [[
'PAULO ROGERIO ROSSETO DE MELO',
'POSTO ROTA 116 DERIVADOS DE PETROLEO LTDA',
'401-4 - EMPRESA INDIVIDUAL IMOBILIARIA'
]]
self.dataframe = self._create_dataframe(data)
prediction_result = self.election_expenser_classifier.predict(self.dataframe)
self.assertEqual(prediction_result[0], False) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cuducos, I fixed the point mentioned above. :) |
||
|
||
prediction_result = self.election_expenser_classifier.predict(self.dataframe) | ||
|
||
self.assertEqual(prediction_result[0], False) | ||
|
||
def test_fit_just_for_formality_because_its_never_used(self): | ||
empty_dataframe = pd.DataFrame() | ||
self.assertTrue(self.election_expenser_classifier.fit(empty_dataframe) is None) | ||
|
||
def test_transform_just_for_formality_because_its_never_used(self): | ||
self.assertTrue(self.election_expenser_classifier.transform() is None) | ||
|
||
def _create_dataframe(self, dataframe_data): | ||
return pd.DataFrame(data=dataframe_data, columns=['congressperson_name', 'name', 'legal_entity']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 says that constants usually should be defined in the module level (not method level), would you mind changing this minor detail?