Skip to content

Commit 9717e9e

Browse files
authored
Merge pull request #1182 from mindsdb/staging
Release 23.8.1.0
2 parents 2812838 + 97b3feb commit 9717e9e

20 files changed

+835
-759
lines changed

.flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
max-line-length = 120
3-
ignore = E275,E402,F821,W503,W504,C408,W391
3+
ignore = E275,E402,F821,W503,W504,C408,W391,E721
44
exclude = .git,__pycache__,docs,docssrc

.github/workflows/ligthtwood.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest]
17-
python-version: ['3.8','3.9']
17+
python-version: ["3.8","3.9","3.10","3.11"]
1818
steps:
1919
- uses: actions/checkout@v2
2020
- name: Set up Python ${{ matrix.python-version }}

lightwood/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'lightwood'
22
__package_name__ = 'lightwood'
3-
__version__ = '23.7.1.0'
3+
__version__ = '23.8.1.0'
44
__description__ = "Lightwood is a toolkit for automatic machine learning model building"
55
__email__ = "community@mindsdb.com"
66
__author__ = 'MindsDB Inc'

lightwood/analysis/explain.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
from dataprep_ml import StatisticalAnalysis
66

7-
from lightwood.helpers.log import log
7+
from lightwood.helpers.log import log, timed
88
from lightwood.api.types import ProblemDefinition, PredictionArguments
99
from lightwood.helpers.ts import get_inferred_timestamps
1010
from lightwood.analysis.base import BaseAnalysisBlock
1111

1212

13+
@timed
1314
def explain(data: pd.DataFrame,
1415
encoded_data: torch.Tensor,
1516
predictions: pd.DataFrame,

lightwood/analysis/nc/calibrate.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,11 @@ def analyze(self, info: Dict[str, object], **kwargs) -> Dict[str, object]:
200200
# save relevant predictions in the caches, then calibrate the ICP
201201
pred_cache = icp_df.pop(f'__predicted_{ns.target}').values
202202
if ns.is_multi_ts and ns.is_classification:
203-
# output['label_encoders'].transform(preds.reshape(-1, 1))
204203
pred_cache = output['label_encoders'].transform([[p[0] for p in pred_cache]])
205204
elif ns.is_multi_ts:
206205
pred_cache = np.array([np.array(p) for p in pred_cache])
206+
elif ns.is_classification:
207+
pred_cache = output['label_encoders'].transform(pred_cache.reshape(-1, 1))
207208

208209
icps[tuple(group)].nc_function.model.prediction_cache = pred_cache
209210
icp_df, y = clean_df(icp_df, ns, output.get('label_encoders', None))

lightwood/api/high_level.py

+2-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from types import ModuleType
32
from typing import Union
43
import dill
54
import pandas as pd
@@ -8,12 +7,8 @@
87
from type_infer.infer import infer_types
98
from lightwood.api.predictor import PredictorInterface
109
from lightwood.api.json_ai import generate_json_ai
11-
import tempfile
12-
from lightwood.api.json_ai import code_from_json_ai as _code_from_json_ai
13-
import importlib.util
10+
from lightwood.helpers.codegen import code_from_json_ai as _code_from_json_ai, _module_from_code, _predictor_from_code
1411
import sys
15-
import random
16-
import string
1712
import gc
1813
import time
1914
from lightwood.helpers.log import log
@@ -107,10 +102,7 @@ def predictor_from_code(code: str) -> PredictorInterface:
107102
108103
:returns: A lightwood ``Predictor`` object
109104
"""
110-
module_name = ''.join(random.choices(string.ascii_uppercase + string.digits, k=12))
111-
module_name += str(time.time()).replace('.', '')
112-
predictor = _module_from_code(code, module_name).Predictor()
113-
return predictor
105+
return _predictor_from_code(code)
114106

115107

116108
def code_from_problem(df: pd.DataFrame, problem_definition: Union[ProblemDefinition, dict]) -> str:
@@ -162,31 +154,6 @@ def predictor_from_state(state_file: str, code: str = None) -> PredictorInterfac
162154
return predictor
163155

164156

165-
def _module_from_code(code: str, module_name: str) -> ModuleType:
166-
"""
167-
Create a python module (containing the generated ``Predictor`` class) from the code. This is both a python object and an associated temporary file on your filesystem
168-
169-
:param code: The ``Predictor``'s code in text form
170-
:param module_name: The name of the newly created module
171-
172-
:returns: A python module object
173-
""" # noqa
174-
dirname = tempfile.gettempdir()
175-
filename = os.urandom(24).hex() + str(time.time()).replace('.', '') + '.py'
176-
path = os.path.join(dirname, filename)
177-
if 'LIGHTWOOD_DEV_SAVE_TO' in os.environ:
178-
path = os.environ['LIGHTWOOD_DEV_SAVE_TO']
179-
180-
with open(path, 'wb') as fp:
181-
fp.write(code.encode('utf-8'))
182-
spec = importlib.util.spec_from_file_location(module_name, fp.name)
183-
temp_module = importlib.util.module_from_spec(spec)
184-
sys.modules[module_name] = temp_module
185-
spec.loader.exec_module(temp_module)
186-
187-
return temp_module
188-
189-
190157
def predictor_from_json_ai(json_ai: JsonAI) -> PredictorInterface:
191158
"""
192159
Creates a ready-to-train ``Predictor`` object based on the details you specified inside your JsonAI.

0 commit comments

Comments
 (0)