Skip to content

Commit de13867

Browse files
authored
Merge pull request #225 from sassoftware/update_imputations
fix: update imputation method to avoid warnings
2 parents 377b659 + 7cf44e0 commit de13867

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/sasctl/_services/model_repository.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from ..core import current_session, delete, get, sasctl_command, RestObj
1919
from .service import Service
2020

21-
2221
FUNCTIONS = {
2322
"Analytical",
2423
"Classification",

src/sasctl/pzmm/write_score_code.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,16 @@ def impute_missing_values(data):
766766
"""
767767
impute_values = \\\n + {"var1": 0, "var2": "", "var3": 125.3}
768768
"""
769-
self.score_code += f"\n{'':4}return data.replace(' .', np.nan).fillna(impute_values).apply(pd.to_numeric, errors='ignore')\n"
770-
"""
771-
772-
return data.replace(' .', np.nan).fillna(impute_values).apply(pd.to_numeric, errors='ignore')
769+
self.score_code += (
770+
f"\n\n{'':4}# Specify downcasting behavior for pandas 2.x to avoid warnings\n"
771+
+ f"{'':4}if int(pd.__version__.split('.')[0]) == 2:\n{'':8}pd.set_option('future.no_silent_downcasting', True)\n"
772+
+ f"{'':4}return data.replace(r'^\\s*\\.$', np.nan, regex=True).fillna(impute_values).infer_objects()\n"
773+
)
774+
"""
775+
# Specify downcasting behavior for pandas 2.x to avoid warnings
776+
if int(pd.__version__.split('.')[0]) == 2:
777+
pd.set_option('future.no_silent_downcasting', True)
778+
return data.replace(r'^\s*\.$', np.nan, regex=True).fillna(impute_values).infer_objects()
773779
"""
774780

775781
# TODO: Needs unit test

tests/integration/test_pymas.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import pytest
1212

13-
1413
pytest.skip(
1514
"PyMAS functionality is deprecated and will be removed in a future release.",
1615
allow_module_level=True,
@@ -241,9 +240,7 @@ def test_from_pickle(train_data, pickle_file):
241240
end;
242241
243242
endpackage;
244-
""".lstrip(
245-
"\n"
246-
)
243+
""".lstrip("\n")
247244

248245
assert isinstance(p, PyMAS)
249246

@@ -343,9 +340,7 @@ def hello_world():
343340
end;
344341
345342
endpackage;
346-
""".lstrip(
347-
"\n"
348-
)
343+
""".lstrip("\n")
349344

350345
f = tmpdir.join("model.py")
351346
f.write(code)

0 commit comments

Comments
 (0)