mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Feature Request] Implement `__iter__` on PythonObject

Open xcloudplatform opened this issue 1 year ago • 1 comments

Review Mojo's 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

xcloudplatform avatar Jun 04 '23 10:06 xcloudplatform

@stumpOS FYI

Mogball avatar Jun 06 '23 18:06 Mogball

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):
    ...

MainRo avatar Jun 20 '23 20:06 MainRo

@stumpOS can you take a look at this?

lattner avatar Jun 23 '23 14:06 lattner

It got deep in my queue. I'll prioritize this for today. Thanks for the ping!

stumpOS avatar Jun 23 '23 16:06 stumpOS

nice, please add to changelog if you haven't already!

lattner avatar Jul 03 '23 20:07 lattner

Yep, PR coming soon

stumpOS avatar Jul 03 '23 20:07 stumpOS