Implement sklearn version in PyWrap

This commit is contained in:
Ricardo Montañana Gómez 2023-11-27 22:34:34 +01:00
parent 82964190f6
commit 4addaefb47
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE

View File

@ -127,10 +127,19 @@ namespace pywrap {
} }
std::string PyWrap::sklearnVersion() std::string PyWrap::sklearnVersion()
{ {
return "1.0"; PyObject* sklearnModule = PyImport_ImportModule("sklearn");
// CPyObject data = PyRun_SimpleString("import sklearn;return sklearn.__version__"); if (sklearnModule == nullptr) {
// std::string result = PyUnicode_AsUTF8(data); errorAbort("Couldn't import sklearn");
// return result; }
PyObject* versionAttr = PyObject_GetAttrString(sklearnModule, "__version__");
if (versionAttr == nullptr || !PyUnicode_Check(versionAttr)) {
Py_XDECREF(sklearnModule);
errorAbort("Couldn't get sklearn version");
}
std::string result = PyUnicode_AsUTF8(versionAttr);
Py_XDECREF(versionAttr);
Py_XDECREF(sklearnModule);
return result;
} }
std::string PyWrap::version(const clfId_t id) std::string PyWrap::version(const clfId_t id)
{ {