Skip to content

Commit

Permalink
address review comments in #2867
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Jan 16, 2020
1 parent 52c4667 commit fddec90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 20 additions & 9 deletions plugins/python/io/NumpyReader.cpp
Expand Up @@ -173,8 +173,8 @@ PyArrayObject* load_npy_script(std::string const& source,
{

MetadataNode m;
std::unique_ptr<plang::Script> script(new plang::Script(source, module, function));
std::unique_ptr<plang::Invocation> method(new plang::Invocation(*script, m, fargs));
plang::Script script(source, module, function);
plang::Invocation method(script, m, fargs);

StringList args = Utils::split(fargs,',');

Expand All @@ -188,10 +188,12 @@ PyArrayObject* load_npy_script(std::string const& source,

}

PyObject *array = PyObject_CallObject(method->m_function, scriptArgs);
PyObject *array = PyObject_CallObject(method.m_function, scriptArgs);
if (!array)
throw pdal_error(plang::getTraceback());

Py_XDECREF(scriptArgs);

return reinterpret_cast<PyArrayObject*>(array);
}

Expand Down Expand Up @@ -220,15 +222,24 @@ void NumpyReader::initialize()
m_args->module,
m_args->function,
m_args->fargs);
if (!PyArray_Check(m_array))
{
std::stringstream errMsg;
errMsg << "Object returned from function '"
<< m_args->function <<
"' in '" << m_filename <<
"' is not a Numpy array";
throw pdal::pdal_error(errMsg.str());
}
}
else if (m_filename.size())
{
m_array = load_npy_file(m_filename);
}
if (!PyArray_Check(m_array))
throw pdal::pdal_error("Object in file '" + m_filename +
"' is not a Numpy array");

if (!PyArray_Check(m_array))
throw pdal::pdal_error("Object in file '" + m_filename +
"' is not a numpy array");
}
}


Expand Down Expand Up @@ -299,9 +310,9 @@ void NumpyReader::addArgs(ProgramArgs& args)
m_order);

args.add("module", "Python module containing the function to run",
m_args->module, "");
m_args->module);
args.add("function", "Function nameto call",
m_args->function, "");
m_args->function);
args.add("fargs", "Args to call function with ", m_args->fargs);

}
Expand Down
2 changes: 0 additions & 2 deletions test/data/plang/threedim.py
Expand Up @@ -4,5 +4,3 @@ def load(filename):
array = np.load(filename)
return array

#a = load('threedim.npy')
#print (a)

0 comments on commit fddec90

Please sign in to comment.