-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Describe the bug
Type hints for the injected functions on a ScmRun are not properly handled. Pycharm has no idea that lineplot
is an available function which is a pretty poor developer experience.
With large container classes we want to provide a range of behaviour without having to lump it all in the same module which is difficult to understand
Currently we inject functionality for:
- netcdf io
- xarray io
- arithemetic operations
- plotting
We also inherit an "OpsMixin" baseclass which correctly sets some magic methods
There are a few ways of achieving this:
- Move to a model similar to xarray which uses inheritance to bring together functionality
https://github.com/pydata/xarray/blob/e2b6f3468ef829b8a83637965d34a164bf3bca78/xarray/core/arithmetic.py#L122
Pandas doesn't use inheritance in the same way, but simply has a huge frame.py file
-
Use composition to perform the same action. That might work well for plotting as it seems to be the common pattern used across xarray and pandas. e.g.
df.plot.line
ords.plot.scatter
. This might cause a large change to the API without some relatively opaque redirection.
See https://github.com/pandas-dev/pandas/blob/d04747c367d00ee03c5d008ce5670892d450e801/pandas/core/series.py#L5782 for pandas accessors -
Add the IO functions to BaseScmRun, removing the need for the injection. The lower level functionality can happen elsewhere in
scmdata.netcdf
, but the method knows what to call.
In reality, the soln could be a mixture of all three.
plotting = composition
arithmetic = inheritance
xarray and NC = methods
@mikapfl Any other suggestions or thoughts?
Failing Test
Pycharm autocompletes lineplot
with the correct type hint information