mojo
mojo copied to clipboard
[Feature Request] Implement `__iter__` on PythonObject
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
when using python list it should not be of opaque type PythonObject. instead, it should be transparently bridged into list like object
What is your motivation for this change?
%%python
package_list = [
"nltk",
"gensim",
"fasttext",
"spacy",
"textblob",
"pytorch_lightning",
"fastai",
"keras_tuner",
"hyperopt",
"pycaret",
"shap",
"eli5",
"catboost",
"xgboost",
"lightgbm",
"prophet",
"opencv-python",
"dlib",
"imbalanced-learn",
"tpot"
]
from PythonInterface import Python
available_packages = []
for package_name in package_list:
try:
Python.import_module(package_name)
available_packages.append(package_name)
except:
pass
available_packages
error: Expression [14]:18:25: 'PythonObject' does not implement the '__iter__' method
for package_name in package_list:
Any other details?
x
@stumpOS FYI
Is there a possible alternative for now? For some tests I would like to iterate over a numpy array (in a for loop).
values = np.random.normal(0.0, 1.0, num_points)
for i in np.nditer(values):
...
@stumpOS can you take a look at this?
It got deep in my queue. I'll prioritize this for today. Thanks for the ping!
nice, please add to changelog if you haven't already!
Yep, PR coming soon