Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move plotting functions to separate modules #808

Merged

Conversation

willschlitzer
Copy link
Contributor

@willschlitzer willschlitzer commented Jan 28, 2021

As mentioned in #685, this is to split up base_plotting.py and move the plotting functions to separate scripts, following the method used by @weiji14 in #686.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.

Notes

  • You can write /format in the first line of a comment to lint the code automatically

@willschlitzer willschlitzer added the maintenance Boring but important stuff for the core devs label Jan 28, 2021
@willschlitzer willschlitzer added this to the 0.3.0 milestone Jan 28, 2021
@willschlitzer
Copy link
Contributor Author

@GenericMappingTools/python I moved all of the plotting functions to their own modules. I'm running into a few style errors that I'm not sure how to address.

pygmt/src/contour.py:98:13: W0212: Access to a protected member _preprocess of a client class (protected-access)
I'm guessing this is because the functions use _preprocess but don't import it, but the tests successfully running makes me assume that it works because _preprocess is in the class that these modules are imported into.

pygmt/base_plotting.py:8:0: R0903: Too few public methods (0/2) (too-few-public-methods)
I'm assuming this is because the class doesn't really "do" all that much specifically, since the functions are all housed in their own modules. I'm assuming this is acceptable, otherwise functions would just be arbitrarily moved back to base_plotting.py.

pygmt/src/text.py:48:4: W0621: Redefining name 'text' from outer scope (line 40) (redefined-outer-name)
I'm guessing "text" is a common/special word, so having it in the name of both a function and module is causing difficulties. Not sure how it should be addressed.

@willschlitzer willschlitzer mentioned this pull request Feb 6, 2021
19 tasks
pygmt/src/text.py Outdated Show resolved Hide resolved
pygmt/src/__init__.py Outdated Show resolved Hide resolved
Comment on lines 43 to 59
from pygmt.src import ( # pylint: disable=import-outside-toplevel
basemap,
coast,
colorbar,
contour,
grdcontour,
grdimage,
grdview,
image,
inset,
legend,
logo,
meca,
plot,
plot3d,
text,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in #808 (comment), could you delete base_plotting.py (can't believe I'm saying this!) and move this import chunk to figure.py? This will fix the pylint R0903: Too few public methods (0/2) (too-few-public-methods) recommendation. Feel free to copy any of the docstrings if needed.

Copy link
Contributor Author

@willschlitzer willschlitzer Feb 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weiji14 I just moved this import string to figure.py and removed imports for base_plotting.py, but when I ran make test I had 196 test failures. I'm not sure what the need for _preprocess is, but it seems to play some sort of role.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking that you placed the imports under class Figure():? I.e. indented 4 spaces? The _preprocess class function activates the correct figure to plot in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...nope 🤦‍♂️

Removed base_plotting.py in 5ac2e07 and actually put the imports in Figure() and it worked (or at least passed all of the tests)!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in #808 (comment), could you delete base_plotting.py (can't believe I'm saying this!) and move this import chunk to figure.py? This will fix the pylint R0903: Too few public methods (0/2) (too-few-public-methods) recommendation. Feel free to copy any of the docstrings if needed.

We should be careful with the changes. There are two different _preprocess() functions in Figure() and BasePlotting. If I understand it correctly, the _preprocess function if BasePlotting override the one in Figure().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seisman The tests are passing; is there an issue with deleting base_plotting.py?

Copy link
Member

@weiji14 weiji14 Feb 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be careful with the changes. There are two different _preprocess() functions in Figure() and BasePlotting. If I understand it correctly, the _preprocess function if BasePlotting override the one in Figure().

I feel like the _preprocess in base_plotting.py was just a dummy placeholder, and the one in figure.py is the actual one used. So probably the other way around? Might need to read up on subclassing, I'm not terribly good at object orientated conventions.

Edit: Yep, the _preprocess in Figure() takes precedence over BasePlotting. See https://stackoverflow.com/questions/12764995/python-overriding-an-inherited-class-method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought BasePlotting() is a subclass of Figure(), now it makes sense to me.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to merge now (after updating the branch), what do you think @seisman?

Deleting base_plotting.py and moving every module to src will cause conflicts in several open PRs (e.g. velo at #525, triangulate at #731, the grdimage work at #750, etc), but we can sort those out later 🙃

Copy link
Member

@seisman seisman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, except a few tiny suggestions.

pygmt/src/__init__.py Outdated Show resolved Hide resolved
pygmt/src/text.py Outdated Show resolved Hide resolved
@weiji14 weiji14 mentioned this pull request Feb 7, 2021
21 tasks
@willschlitzer willschlitzer merged commit 540ac0f into GenericMappingTools:master Feb 7, 2021
@willschlitzer willschlitzer deleted the move-plotting-functions branch February 7, 2021 10:21
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
*Move plotting functions from base_plotting.py to separate functions in pygmt/src
*Add plotting function imports to pygmt/src/__init__.py
*Import plotting functions directly into figure.py
*Remove base_plotting.py

Co-authored-by: Wei Ji <[email protected]>
Co-authored-by: Dongdong Tian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants