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

Support datetimes in histogram operation #2719

Merged
merged 9 commits into from May 28, 2018

Conversation

Projects
None yet
2 participants
@philippjfr
Copy link
Contributor

philippjfr commented May 23, 2018

This PR makes it possible to generate a histogram from datetime data as requested in #2713 and pyviz/hvplot#12. This is consistent with plt.hist which also handle datetimes and can be useful to determine the sampling frequency of a dataset.

  • Implements #2713
  • Adds unit tests
@philippjfr

This comment has been minimized.

Copy link
Contributor Author

philippjfr commented May 24, 2018

Ready to merge when tests pass.

@philippjfr philippjfr added this to the v1.10.5 milestone May 24, 2018

@@ -204,7 +204,7 @@ def coords(cls, dataset, dim, ordered=False, expanded=False, edges=False):
if edges and not isedges:
data = cls._infer_interval_breaks(data)
elif not edges and isedges:
data = np.convolve(data, [0.5, 0.5], 'valid')
data = data[:-1] + np.diff(data)/2.

This comment has been minimized.

@jlstevens

jlstevens May 25, 2018

Contributor

Much simpler than a weird and confusing convolve call!

widths = np.diff(edges)
lims = hist.range(0) + hist.range(1)
return edges[:-1], hist_vals, widths, lims
return edges[:-1], hist_vals, widths, xlim+ylim, datetime

This comment has been minimized.

@jlstevens

jlstevens May 25, 2018

Contributor

Instead of True/False maybe the more general thing would be to return the type itself (or some more general information about the type than a boolean just about datetimes)? This could allow for other conditional dimension type formatters in future.

If nothing else, grepping for datetime is a bit of a nightmare so it should be called isdatetime or similar...

@philippjfr philippjfr force-pushed the datetime_histogram branch from c3a2be0 to 400540e May 26, 2018

@philippjfr

This comment has been minimized.

Copy link
Contributor Author

philippjfr commented May 26, 2018

Done.

widths = np.diff(edges)
lims = hist.range(0) + hist.range(1)
return edges[:-1], hist_vals, widths, lims
return edges[:-1], hist_vals, widths, xlim+ylim, isdatetime

This comment has been minimized.

@jlstevens

jlstevens May 28, 2018

Contributor

I can still conceive of wanting support for other numeric types one day (e.g rationals?) but this is fine for now. We can use a general type specifier when we find ourselves needing to do something similar for another type. This this fine for now.

@jlstevens

This comment has been minimized.

Copy link
Contributor

jlstevens commented May 28, 2018

Looks good. Merging.

@jlstevens jlstevens merged commit 2798bbc into master May 28, 2018

4 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.005%) to 82.702%
Details
s3-reference-data-cache Tests passing no test data changes required.
Details

@philippjfr philippjfr deleted the datetime_histogram branch Jul 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.