Skip to content

Commit f126071

Browse files
authored
Merge pull request #179 from Minku-Koo/osskoo
to update python code for clean code
2 parents 9a93481 + bb050f3 commit f126071

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

python/pandasCommand.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ def _vp_get_columns_list(df):
3636
cInfo['value'] = "'{}'".format(c)
3737
elif type(c).__name__ == 'Timestamp':
3838
cInfo['value'] = str(c)
39+
3940
# category - iopub data rate limit issue...
41+
cInfo['category'] = []
4042
if str(df[c].dtype) == 'object':
4143
uniqValues = df[c].dropna().unique()
4244
if len(uniqValues) <= 20:
4345
cInfo['category'] = [{ "value": "'{}'".format(u) if type(u) == str else u, "label": u } for u in uniqValues]
44-
else:
45-
cInfo['category'] = []
46-
else:
47-
cInfo['category'] = []
46+
4847
colList.append(cInfo)
4948
return colList
5049

python/userCommand.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import fitz
1111
import nltk
1212
nltk.download('punkt')
13+
1314
######
1415
# Visual Python: Data Analysis > PDF
1516
######
@@ -43,6 +44,7 @@ def vp_pdf_get_sentence(fname_lst):
4344
df = _vp_pd.concat([df,df_doc])
4445

4546
return df.reset_index().drop('index', axis=1)
47+
4648
######
4749
# Visual Python: Data Analysis > Frame
4850
######
@@ -63,6 +65,7 @@ def vp_drop_outlier(df, col, weight=1.5):
6365
df_res = df.drop(outlier_index).copy()
6466

6567
return df_res
68+
6669
######
6770
# Visual Python: Machine Learning > Model Info
6871
######
@@ -74,10 +77,12 @@ def vp_create_feature_importances(model, X_train=None, sort=False):
7477

7578
df_i = _vp_pd.DataFrame(model.feature_importances_, index=feature_names, columns=['Feature_importance'])
7679
df_i['Percentage'] = 100 * (df_i['Feature_importance'] / df_i['Feature_importance'].max())
77-
if sort: df_i.sort_values(by='Feature_importance', ascending=False, inplace=True)
80+
if sort:
81+
df_i.sort_values(by='Feature_importance', ascending=False, inplace=True)
7882
df_i = df_i.round(2)
7983

8084
return df_i
85+
8186
######
8287
# Visual Python: Machine Learning > Model Info
8388
######
@@ -91,10 +96,13 @@ def vp_plot_feature_importances(model, X_train=None, sort=False, top_count=0):
9196
df_i['Percentage'].sort_values().plot(kind='barh')
9297
else:
9398
df_i['Percentage'].plot(kind='barh')
99+
94100
_vp_plt.xlabel('Feature importance Percentage')
95101
_vp_plt.ylabel('Features')
96-
97102
_vp_plt.show()
103+
104+
return
105+
98106
######
99107
# Visual Python: Visualization > Seaborn
100108
######
@@ -134,4 +142,6 @@ def _single(ax):
134142
for idx, ax in _vp_np.ndenumerate(axs):
135143
_single(ax)
136144
else:
137-
_single(axs)
145+
_single(axs)
146+
147+
return

python/variableCommand.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import numpy as _vp_np
2+
import random as _vp_rd
13
"""
24
Search Variables
35
"""
@@ -77,8 +79,6 @@ def _vp_get_profiling_list():
7779

7880
return result
7981

80-
import numpy as _vp_np
81-
import random as _vp_rd
8282
def _vp_sample(data, sample_cnt):
8383
"""
8484
Sampling data
@@ -94,16 +94,13 @@ def _vp_sample(data, sample_cnt):
9494
return data[_vp_np.random.choice(data.shape[0], sample_cnt, replace=False)]
9595
elif dataType == 'list':
9696
return _vp_rd.choices(data, k=sample_cnt)
97+
9798
return data
9899

99100
def _vp_check_module_loaded(fname_list):
100101
"""
101102
Check if this module is loaded
102103
"""
103-
result = []
104-
for fname in fname_list:
105-
if fname in globals():
106-
result.append(True)
107-
else:
108-
result.append(False)
104+
result = [True if fname in globals() else False for fname in fname_list]
105+
109106
return result

python/visualizationCommand.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ def _vp_seaborn_show_values(axs, precision=1, space=0.01):
77
pstr = '{:.' + str(precision) + 'f}'
88

99
def _single(ax):
10-
# check orient
10+
# check orient / if 0
1111
orient = 'v'
12-
if len(ax.patches) == 1:
13-
# check if 0
14-
if ax.patches[0].get_x() == 0:
15-
orient = 'h'
12+
if len(ax.patches) == 1 and ax.patches[0].get_x() == 0:
13+
orient = 'h'
1614
else:
1715
# compare 0, 1 patches
1816
p0 = ax.patches[0]
@@ -36,7 +34,7 @@ def _single(ax):
3634
ax.text(_x, _y, value, ha='left')
3735

3836
if isinstance(axs, _vp_np.ndarray):
39-
for idx, ax in _vp_np.ndenumerate(axs):
37+
for _, ax in _vp_np.ndenumerate(axs):
4038
_single(ax)
4139
else:
4240
_single(axs)

0 commit comments

Comments
 (0)