| Conditions | 1 |
| Total Lines | 60 |
| Code Lines | 39 |
| Lines | 21 |
| Ratio | 35 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import pytest |
||
| 4 | @pytest.fixture |
||
| 5 | def client_pandas_tabular_implementation(): |
||
| 6 | from so_magic.data.interfaces import TabularRetriever, TabularIterator, TabularMutator |
||
| 7 | |||
| 8 | View Code Duplication | class TestPDTabularRetrieverDelegate(TabularRetriever): |
|
|
|
|||
| 9 | """The observation object is the same as the one you return from 'from_json_lines'""" |
||
| 10 | |||
| 11 | @classmethod |
||
| 12 | def column(cls, identifier, data): |
||
| 13 | return data.observations[identifier] |
||
| 14 | |||
| 15 | def row(self, identifier, data): |
||
| 16 | return data.observations.loc(identifier) |
||
| 17 | |||
| 18 | @classmethod |
||
| 19 | def nb_columns(cls, data): |
||
| 20 | return len(data.observations.columns) |
||
| 21 | |||
| 22 | @classmethod |
||
| 23 | def nb_rows(cls, data): |
||
| 24 | return len(data.observations) |
||
| 25 | |||
| 26 | @classmethod |
||
| 27 | def get_numerical_attributes(cls, data): |
||
| 28 | return data.observations._get_numeric_data().columns.values |
||
| 29 | |||
| 30 | |||
| 31 | class TestPDTabularIteratorDelegate(TabularIterator): |
||
| 32 | """The observation object is the same as the one your return from 'from_json_lines'""" |
||
| 33 | |||
| 34 | def columnnames(self, data): |
||
| 35 | return list(data.observations.columns) |
||
| 36 | |||
| 37 | @classmethod |
||
| 38 | def iterrows(cls, data): |
||
| 39 | return iter(data.observations.iterrows()) |
||
| 40 | |||
| 41 | @classmethod |
||
| 42 | def itercolumns(cls, data): |
||
| 43 | return iter(data.observations[column] for column in data.observations.columns) |
||
| 44 | |||
| 45 | |||
| 46 | class TestPDTabularMutatorDelegate(TabularMutator): |
||
| 47 | |||
| 48 | @classmethod |
||
| 49 | def add_column(cls, datapoints, values, new_attribute, **kwargs): |
||
| 50 | datapoints.observations[new_attribute] = values |
||
| 51 | |||
| 52 | |||
| 53 | BACKEND = { |
||
| 54 | 'backend_id': 'test-pd', |
||
| 55 | 'backend_name': 'test-pandas', |
||
| 56 | 'interfaces': [ |
||
| 57 | TestPDTabularRetrieverDelegate, |
||
| 58 | TestPDTabularIteratorDelegate, |
||
| 59 | TestPDTabularMutatorDelegate, |
||
| 60 | ] |
||
| 61 | } |
||
| 62 | |||
| 63 | return BACKEND |
||
| 64 | |||
| 87 |