h2oai / h2o-3

H2O is an Open Source, Distributed, Fast & Scalable Machine Learning Platform: Deep Learning, Gradient Boosting (GBM) & XGBoost, Random Forest, Generalized Linear Modeling (GLM with Elastic Net), K-Means, PCA, Generalized Additive Models (GAM), RuleFit, Support Vector Machine (SVM), Stacked Ensembles, Automatic Machine Learning (AutoML), etc.
http://h2o.ai
Apache License 2.0
6.88k stars 1.99k forks source link

H2OFrame truthness only partially compatible with pandas DataFrame on Py2 and completely incompatible on Py3 #9057

Open exalate-issue-sync[bot] opened 1 year ago

exalate-issue-sync[bot] commented 1 year ago

Our Python implementation of {{H2OFrame}} truthness is very inconsistent:

Python2: we override {{__nonzero__}} to support boolean conversion in Py2 {code} bool(h2o.H2OFrame()) # raise AssertionError bool(h2o.H2OFrame([])) # False bool(h2o.H2OFrame([1]) # True bool(h2o.H2OFrame([1, 1]) # raise H2OValueError from our nonzero impl {code}

Python3: we don't override {{__bool__}}, therefore delegating boolean conversions to {{__len__}} in Py3 and skipping {{__nonzero__}} logic {code} bool(h2o.H2OFrame()) # raise AssertionError bool(h2o.H2OFrame([])) # False bool(h2o.H2OFrame([1]) # True bool(h2o.H2OFrame([1, 1]) # True {code}

compare with Pandas DataFrame: {code} bool(pandas.DataFrame()) # raise ValueError: the truth value of a DataFrame is ambiguous. bool(pandas.DataFrame([])) # raise ValueError... bool(pandas.DataFrame([1]) # raise ValueError... bool(pandas.DataFrame([1, 1]) # raise ValueError... {code}

h2o-ops commented 1 year ago

JIRA Issue Migration Info

Jira Issue: PUBDEV-6574 Assignee: New H2O Bugs Reporter: Sebastien Poirier State: Open Fix Version: N/A Attachments: N/A Development PRs: N/A