Conditions | 1 |
Total Lines | 80 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
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 numpy as np |
||
57 | def display_basic_stats(self): |
||
58 | """Display basic statistics of array""" |
||
59 | pstr_list = [] |
||
60 | |||
61 | pstr_struct_header1 = '\033[1m' + "Basic Statistics " + '\033[0m' |
||
62 | |||
63 | pstr_list.append(pstr_struct_header1) |
||
64 | |||
65 | pstr_meanstdhead = ( |
||
66 | "\n" |
||
67 | "{0:^15}" |
||
68 | "{1:^15}" |
||
69 | ).format("Mean", "Std Dev") |
||
70 | pstr_meanstdhead = ( |
||
71 | "{0:^{self.col_width}}" |
||
72 | ).format(pstr_meanstdhead, self=self) |
||
73 | pstr_list.append(pstr_meanstdhead) |
||
74 | |||
75 | pstr_meanstdstat = ( |
||
76 | "{self.mean:^15.{self.precision}}" |
||
77 | "{self.std:^15.{self.precision}}" |
||
78 | ).format(self=self) |
||
79 | pstr_meanstdstat = ( |
||
80 | "{0:^{self.col_width}}" |
||
81 | ).format(pstr_meanstdstat, self=self) |
||
82 | pstr_list.append(pstr_meanstdstat) |
||
83 | |||
84 | pstr_3pthead = ( |
||
85 | "\n" |
||
86 | "{0:^10}" |
||
87 | "{1:^10}" |
||
88 | "{2:^10}" |
||
89 | "{3:^10}" |
||
90 | "{4:^10}" |
||
91 | ).format('Min,', '1Q', 'Median', '3Q', 'Max') |
||
92 | pstr_3pthead = ( |
||
93 | "{0:^{self.col_width}}" |
||
94 | ).format(pstr_3pthead, self=self) |
||
95 | pstr_list.append(pstr_3pthead) |
||
96 | |||
97 | pstr_3ptstat = ( |
||
98 | "{self.min:^10.{self.precision}}" |
||
99 | "{self.firstquartile:^10.{self.precision}}" |
||
100 | "{self.median:^10.{self.precision}}" |
||
101 | "{self.thirdquartile:^10.{self.precision}}" |
||
102 | "{self.max:^10.{self.precision}}" |
||
103 | ).format(self=self) |
||
104 | pstr_3ptstat = ( |
||
105 | "{0:^{self.col_width}}" |
||
106 | ).format(pstr_3ptstat, self=self) |
||
107 | pstr_list.append(pstr_3ptstat) |
||
108 | |||
109 | pstr_clhead = ( |
||
110 | "\n" |
||
111 | "{0:^10}" |
||
112 | "{1:^10}" |
||
113 | "{2:^10}" |
||
114 | "{3:^10}" |
||
115 | "{4:^10}" |
||
116 | "{5:^10}" |
||
117 | ).format('-99 CL', '-95 CL', '-68 CL', '+68 CL', '+95 CL', '+99 CL') |
||
118 | pstr_clhead = ( |
||
119 | "{0:^{self.col_width}}" |
||
120 | ).format(pstr_clhead, self=self) |
||
121 | pstr_list.append(pstr_clhead) |
||
122 | |||
123 | pstr_clstat = ( |
||
124 | "{self.cl_99[0]:^10.{self.precision}}" |
||
125 | "{self.cl_95[0]:^10.{self.precision}}" |
||
126 | "{self.cl_68[0]:^10.{self.precision}}" |
||
127 | "{self.cl_68[1]:^10.{self.precision}}" |
||
128 | "{self.cl_95[1]:^10.{self.precision}}" |
||
129 | "{self.cl_99[1]:^10.{self.precision}}" |
||
130 | ).format(self=self) |
||
131 | pstr_clstat = ( |
||
132 | "{0:^{self.col_width}}" |
||
133 | ).format(pstr_clstat, self=self) |
||
134 | pstr_list.append(pstr_clstat) |
||
135 | |||
136 | return pstr_list |
||
137 | |||
258 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.