Skip to content

Allow pandas.Series inputs to fig.histogram and pygmt.info#1329

Merged
weiji14 merged 3 commits intomasterfrom
histogram_pandas_series
Jun 20, 2021
Merged

Allow pandas.Series inputs to fig.histogram and pygmt.info#1329
weiji14 merged 3 commits intomasterfrom
histogram_pandas_series

Conversation

@weiji14
Copy link
Member

@weiji14 weiji14 commented Jun 11, 2021

Description of proposed changes

Let 1D pandas.Series inputs work properly by modifying the virtualfile_from_data function. Also added two tests in test_histogram.py and test_info.py to ensure this works.

The implementation works by checking whether the input data is a pandas.Series, and then use _data = np.atleast_2d(np.asanyarray(data).T). Specifically, duck-typing is used to see if a to_frame (i.e. to DataFrame) function exists. This duck-typing should theoretically work for pandas.Series and dask.Series objects:

Fixes #1253

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.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@weiji14 weiji14 added the bug Something isn't working label Jun 11, 2021
@weiji14 weiji14 added this to the 0.4.0 milestone Jun 11, 2021
@weiji14 weiji14 self-assigned this Jun 11, 2021
Let 1D `pandas.Series` inputs work properly by refactoring
the `virtualfile_from_data` function. Also added two tests in
test_histogram.py and test_info.py to ensure this works.
@weiji14 weiji14 force-pushed the histogram_pandas_series branch from 9a0c285 to 9ff022d Compare June 11, 2021 03:32
@weiji14 weiji14 marked this pull request as ready for review June 19, 2021 10:31
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.

@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label Jun 19, 2021
@weiji14 weiji14 merged commit d9df659 into master Jun 20, 2021
@weiji14 weiji14 deleted the histogram_pandas_series branch June 20, 2021 02:05
@weiji14 weiji14 removed the final review call This PR requires final review and approval from a second reviewer label Jun 20, 2021
maxrjones pushed a commit that referenced this pull request Jun 20, 2021
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…ppingTools#1329)

Let 1D pandas.Series inputs work properly by modifying
the virtualfile_from_data function. Also added two tests
in test_histogram.py and test_info.py to ensure this works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Histogram doesn't work for pandas.Series

3 participants