Gurobi / gurobipy-pandas

Convenience wrapper for building optimization models from pandas data
https://gurobipy-pandas.readthedocs.io
Apache License 2.0
92 stars 15 forks source link

Help gurobipy users by erroring out when they use camel case #47

Closed simonbowly closed 1 year ago

simonbowly commented 1 year ago

gurobipy natives might run into some confusion with model.addVars and gppd.add_vars. For the global functions, python3.10 has a nice feature to help:

>>> gppd.addVars
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'gurobipy_pandas' has no attribute 'addVars'. Did you mean: 'add_vars'?

But this may not catch all cases (especially in accessors where we just call down to find a gurobipy object method) and won't help for py39 and earlier. For common cases (e.g. setAttr on a series accessor, where we will use set_attr), we can consider throwing the above error ourselves to help guide users.

simonbowly commented 1 year ago

We should do this for the accessors via __getattr__ to pick up accidental camel case use and throw a nice error

simonbowly commented 1 year ago

Done for the series accessor. Users will get did you mean set_attr instead of 'gurobipy.Var' object has no attribute 'setAttr' to direct them towards snake case for the accessor.

For the dataframe accessor, addVars/addConstrs already throws a reasonable attribute error.