Allow pandas.DataFrame table and 1D/2D numpy array inputs into pygmt.info#574
Merged
Allow pandas.DataFrame table and 1D/2D numpy array inputs into pygmt.info#574
Conversation
Also renamed 'fname' argument to 'table' since `info` supports both file name inputs and pandas.DataFrame tables now.
5 tasks
weiji14
commented
Sep 7, 2020
weiji14
commented
Sep 7, 2020
| if kind == "file": | ||
| file_context = dummy_context(table) | ||
| elif kind == "matrix": | ||
| _table = np.asanyarray(table) |
Member
Author
There was a problem hiding this comment.
Just FYI, this line converts pandas.DataFrame into a numpy.ndarray, while allowing numpy.ndarray objects to just pass through. A bit easier than using _table = table.values if hasattr(table, values) else table, and I think this allows for Python lists to work too (though I haven't tested it).
See also:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
Let pygmt.info support pandas.DataFrame and 1D/2D numpy array inputs. Enables code like so:
I've renamed the 'fname' argument to 'table' (which is a 💥 breaking change) since
infosupports both file name inputs and pandas.DataFrame tables now.Fixes #564
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.