Skip to content

Commit d3a97f9

Browse files
committed
update: setuptools and m1 support
1 parent 6f49bfe commit d3a97f9

File tree

10 files changed

+64
-30
lines changed

10 files changed

+64
-30
lines changed

.github/workflows/linux.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
uses: actions/setup-python@v5
2222
with:
2323
python-version: ${{ matrix.python-version }}
24-
architecture: x64
2524
- run: make build_deps
2625
- run: pip install -r requirements-nn.txt
2726
- run: pip install .[all]

.github/workflows/macos.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,33 @@ jobs:
77
strategy:
88
matrix:
99
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
10-
macos-version: ['macos-12', 'macos-latest']
10+
macos-version: ['macos-13', 'macos-latest']
1111
include:
1212
- experimental: false
1313
- macos-version: 'macos-latest'
1414
experimental: true
15+
- python-version: '3.9'
16+
experimental: true
1517
- python-version: '3.13'
1618
experimental: true
1719
fail-fast: false
1820
runs-on: ${{ matrix.macos-version }}
1921
continue-on-error: ${{ matrix.experimental }}
20-
name: Test py ${{ matrix.python-version }}
22+
name: Test py ${{ matrix.python-version }} ${{ matrix.macos-version }}
2123
steps:
2224
- uses: actions/checkout@master
2325
- name: Setup Python
2426
uses: actions/setup-python@v5
2527
with:
2628
python-version: ${{ matrix.python-version }}
27-
architecture: x64
2829
- run: make build_deps
2930
- run: pip install -r requirements-nn.txt
3031
- run: pip install .[all]
3132
- run: make test
3233
- run: make dist_wheel
3334
- uses: actions/upload-artifact@v4
3435
with:
35-
name: wheel-${{ matrix.python-version }}
36+
name: wheel-${{ matrix.python-version }}-${{ matrix.macos-version }}
3637
path: dist/*.whl
3738
release:
3839
needs: [test]

.github/workflows/windows.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
uses: actions/setup-python@v5
2222
with:
2323
python-version: ${{ matrix.python-version }}
24-
architecture: x64
2524
- run: make build_deps
2625
- run: pip install -r requirements-nn.txt
2726
- run: pip install .[all]

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Add
11+
- Added `ax` support for `plot`
12+
- Added `Apple M1` support
13+
1014
## [0.1.4] - 2024-11-03
1115

1216
### Add

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
[project]
22
name = "toad"
33
description = "Toad is dedicated to facilitating model development process, especially for a scorecard."
4-
requires-python = ">=3.7"
4+
requires-python = ">=3.9"
55
license = {file = "LICENSE"}
66
authors = [{name = "Secbone", email = "secbone@gmail.com"}]
77
classifiers = [
88
'Operating System :: POSIX',
99
'Operating System :: Microsoft :: Windows',
1010
'Operating System :: MacOS :: MacOS X',
11-
'Programming Language :: Python :: 3.8',
1211
'Programming Language :: Python :: 3.9',
1312
'Programming Language :: Python :: 3.10',
1413
'Programming Language :: Python :: 3.11',

requirements.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
Cython >= 0.29.15
2-
numpy >= 1.20
1+
Cython <= 0.29.15 ; python_version < "3.10"
2+
Cython >= 0.29.15 ; python_version >= "3.10"
3+
numpy <= 1.24 ; python_version < "3.10"
4+
numpy >= 1.24 ; python_version >= "3.10"
35
pandas >= 1.5
46
scipy
57
joblib >= 0.12
68
scikit-learn >= 0.21
79
seaborn >= 0.10.0
10+
setuptools

setup.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ universal=1
66

77
[aliases]
88
test=pytest
9-
10-
[metadata]
11-
description-file = README.md
12-
license_file = LICENSE

toad/plot.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def badrate_plot(frame, x = None, target = 'target', by = None,
107107
return unpack_tuple(res)
108108

109109

110-
def corr_plot(frame, figure_size = (20, 15)):
110+
def corr_plot(frame, figure_size = (20, 15), ax = None):
111111
"""plot for correlation
112112
113113
Args:
@@ -133,12 +133,13 @@ def corr_plot(frame, figure_size = (20, 15)):
133133
annot = True,
134134
fmt = '.2f',
135135
figure_size = figure_size,
136+
ax = ax,
136137
)
137138

138139
return map_plot
139140

140141

141-
def proportion_plot(x = None, keys = None):
142+
def proportion_plot(x = None, keys = None, ax = None):
142143
"""plot for comparing proportion in different dataset
143144
144145
Args:
@@ -175,12 +176,13 @@ def proportion_plot(x = None, keys = None):
175176
y = 'proportion',
176177
hue = 'keys',
177178
data = prop_data,
179+
ax = ax,
178180
)
179181

180182
return prop_plot
181183

182184

183-
def roc_plot(score, target, compare = None, figsize = (14, 10)):
185+
def roc_plot(score, target, compare = None, figsize = (14, 10), ax = None):
184186
"""plot for roc
185187
186188
Args:
@@ -193,7 +195,9 @@ def roc_plot(score, target, compare = None, figsize = (14, 10)):
193195
"""
194196
auc, fpr, tpr, thresholds = AUC(score, target, return_curve = True)
195197

196-
fig, ax = plt.subplots(1, 1, figsize = figsize)
198+
if ax is None:
199+
fig, ax = plt.subplots(1, 1, figsize = figsize)
200+
197201
ax.plot(fpr, tpr, label = 'ROC curve (area = %0.5f)' % auc)
198202
ax.fill_between(fpr, tpr, alpha = 0.3)
199203
if compare is not None:
@@ -206,7 +210,7 @@ def roc_plot(score, target, compare = None, figsize = (14, 10)):
206210

207211
return ax
208212

209-
def ks_plot(score, target, figsize = (14, 10)):
213+
def ks_plot(score, target, figsize = (14, 10), ax = None):
210214
"""plot for ks
211215
212216
Args:
@@ -219,7 +223,9 @@ def ks_plot(score, target, figsize = (14, 10)):
219223
"""
220224
fpr, tpr, thresholds = roc_curve(target, score)
221225

222-
fig, ax = plt.subplots(1, 1, figsize = figsize)
226+
if ax is None:
227+
fig, ax = plt.subplots(1, 1, figsize = figsize)
228+
223229
ax.plot(thresholds[1 : ], tpr[1 : ], label = 'tpr')
224230
ax.plot(thresholds[1 : ], fpr[1 : ], label = 'fpr')
225231
ax.plot(thresholds[1 : ], (tpr - fpr)[1 : ], label = 'ks')
@@ -235,7 +241,8 @@ def ks_plot(score, target, figsize = (14, 10)):
235241

236242
return ax
237243

238-
def bin_plot(frame, x = None, target = 'target', iv = True, annotate_format = ".2f", return_frame = False, figsize = (12, 6)):
244+
def bin_plot(frame, x = None, target = 'target', iv = True, annotate_format = ".2f",
245+
return_frame = False, figsize = (12, 6), ax = None):
239246
"""plot for bins
240247
241248
Args:
@@ -258,18 +265,21 @@ def bin_plot(frame, x = None, target = 'target', iv = True, annotate_format = ".
258265
target = temp_name
259266

260267
table = feature_bin_stats(frame, x, target)
261-
fig, prop_ax = plt.subplots(figsize=figsize)
262-
prop_ax = tadpole.barplot(
268+
269+
if ax is None:
270+
fig, ax = plt.subplots(figsize=figsize)
271+
272+
ax = tadpole.barplot(
263273
x = x,
264274
y = 'prop',
265275
data = table,
266276
color = '#82C6E2',
267-
ax = prop_ax,
277+
ax = ax,
268278
)
269279

270-
prop_ax = add_annotate(prop_ax, format = annotate_format)
280+
ax = add_annotate(ax, format = annotate_format)
271281

272-
badrate_ax = prop_ax.twinx()
282+
badrate_ax = ax.twinx()
273283
badrate_ax.grid(False)
274284

275285
badrate_ax = tadpole.lineplot(
@@ -284,10 +294,10 @@ def bin_plot(frame, x = None, target = 'target', iv = True, annotate_format = ".
284294
badrate_ax = add_annotate(badrate_ax, format = annotate_format)
285295

286296
if iv:
287-
prop_ax = reset_ylim(prop_ax)
288-
prop_ax = add_text(prop_ax, 'IV: {:.5f}'.format(table['iv'].sum()))
297+
ax = reset_ylim(ax)
298+
ax = add_text(ax, 'IV: {:.5f}'.format(table['iv'].sum()))
289299

290-
res = (prop_ax,)
300+
res = (ax,)
291301

292302
if return_frame:
293303
res += (table,)

toad/utils/decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class xgb_loss(Decorator):
221221
>>> model = xgb.XGBClassifier(objective = xgb_func)
222222
"""
223223
def wrapper(self, pred, label):
224-
from scipy.misc import derivative
224+
from .func import derivative
225225

226226
def partial_func(x):
227227
return self.call(x, label, **self.kwargs)

toad/utils/func.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,26 @@ def get_dummies(dataframe, exclude = None, binary_drop = False, **kwargs):
408408

409409
data = pd.get_dummies(dataframe, columns = columns, **kwargs)
410410
return data
411+
412+
413+
414+
def derivative(func, x0, dx=1.0, n=1, args=()):
415+
"""calculate derivative of function at x0 for order 3
416+
"""
417+
from numpy import array, prod
418+
419+
order = 3
420+
421+
if n == 1:
422+
weights = array([-1, 0, 1]) / 2.0
423+
elif n == 2:
424+
weights = array([1, -2.0, 1])
425+
else:
426+
raise ValueError('n must be 1 or 2')
427+
428+
val = 0.0
429+
ho = order >> 1
430+
for k in range(order):
431+
val += weights[k] * func(x0 + (k - ho) * dx, *args)
432+
return val / prod((dx,) * n, axis=0)
433+

0 commit comments

Comments
 (0)