kmnhan / erlabpy

Complete python workflow for Angle-Resolved Photoemission Spectroscopy (ARPES)
https://erlabpy.readthedocs.io
GNU General Public License v3.0
6 stars 7 forks source link

Make accessor namespace opt-in #25

Open kmnhan opened 6 months ago

kmnhan commented 6 months ago

Description

It is recommended to provide a single accessor under the package namespace. (See https://github.com/pydata/xarray/issues/1080)

Currently, we have multiple callable accessors in the top level namespace of xarray.DataArray, but this is not good practice!

Possible solutions

The best way is to move all these accessors to a single accessor namespace:

Current New
da.qplot da.er.qplot
da.qshow da.er.qshow
da.qsel da.er.qsel
da.kspace da.er.kspace
da.modelfit da.er.modelfit
da.parallel_fit da.er.parallel_fit
ds.modelfit ds.er.modelfit

However, we lose the convenience of calling these functions directly. As a workaround, we should add an opt-in environment variable to enable the top-level accessors. This way, users can choose to use the old syntax if they prefer!

kmnhan commented 4 months ago

Recently, I'm leaning towards making this an opt-out feature, or to not implementing it altogether. Although the pythonic way is obviously to make it an opt-in feature, I don't think better syntax uniformity is worth the extra code complexity. Besides, if we're not going to add any more accessors, the current number of accessors are modest, and I don't think they will cause any confusion if we just document them properly.

Maybe we should try to reduce the number of accessors instead by merging some of them. For instance, we could merge modelfit and parallel_fit into a single qfit accessor to keep consistency.