From 250861059b106371cb232456eeccd6d9e97d8f00 Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Wed, 14 Nov 2018 11:36:59 -0800 Subject: TST, DOC: enable refguide_check * ported the refguide_check module from SciPy for usage in NumPy docstring execution/ verification; added the refguide_check run to Azure Mac OS CI * adjusted NumPy docstrings such that refguide_check passes --- numpy/lib/histograms.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'numpy/lib/histograms.py') diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index 482eabe14..7b229cc89 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -645,7 +645,7 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): >>> hist_0, bins_0 = np.histogram(arr[group_id == 0], bins='auto') >>> hist_1, bins_1 = np.histogram(arr[group_id == 1], bins='auto') - >>> hist_0; hist1 + >>> hist_0; hist_1 array([1, 1, 1]) array([2, 1, 1, 2]) >>> bins_0; bins_1 @@ -748,14 +748,14 @@ def histogram(a, bins=10, range=None, normed=None, weights=None, >>> np.histogram([1, 2, 1], bins=[0, 1, 2, 3]) (array([0, 2, 1]), array([0, 1, 2, 3])) >>> np.histogram(np.arange(4), bins=np.arange(5), density=True) - (array([ 0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4])) + (array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4])) >>> np.histogram([[1, 2, 1], [1, 0, 1]], bins=[0,1,2,3]) (array([1, 4, 1]), array([0, 1, 2, 3])) >>> a = np.arange(5) >>> hist, bin_edges = np.histogram(a, density=True) >>> hist - array([ 0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5]) + array([0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5]) >>> hist.sum() 2.4999999999999996 >>> np.sum(hist * np.diff(bin_edges)) @@ -770,8 +770,9 @@ def histogram(a, bins=10, range=None, normed=None, weights=None, >>> rng = np.random.RandomState(10) # deterministic random data >>> a = np.hstack((rng.normal(size=1000), ... rng.normal(loc=5, scale=2, size=1000))) - >>> plt.hist(a, bins='auto') # arguments are passed to np.histogram + >>> _ = plt.hist(a, bins='auto') # arguments are passed to np.histogram >>> plt.title("Histogram with 'auto' bins") + Text(0.5, 1.0, "Histogram with 'auto' bins") >>> plt.show() """ -- cgit v1.2.1 From d2a6daead874762f992532106502c448a9d43758 Mon Sep 17 00:00:00 2001 From: mattip Date: Mon, 21 Jan 2019 23:42:56 +0200 Subject: DOC: remove python2-only methods, small cleanups --- numpy/lib/histograms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'numpy/lib/histograms.py') diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index 7b229cc89..b00f4c372 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -461,7 +461,8 @@ def _histogram_bin_edges_dispatcher(a, bins=None, range=None, weights=None): @array_function_dispatch(_histogram_bin_edges_dispatcher) def histogram_bin_edges(a, bins=10, range=None, weights=None): r""" - Function to calculate only the edges of the bins used by the `histogram` function. + Function to calculate only the edges of the bins used by the `histogram` + function. Parameters ---------- -- cgit v1.2.1 From 6c21238ac334e916fd4c4c77c3cea4224e33cf3e Mon Sep 17 00:00:00 2001 From: mattip Date: Tue, 22 Jan 2019 21:41:43 +0200 Subject: DOC: fixes from review --- numpy/lib/histograms.py | 1 + 1 file changed, 1 insertion(+) (limited to 'numpy/lib/histograms.py') diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index b00f4c372..bd44d2732 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -609,6 +609,7 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): 'Sqrt' .. math:: n_h = \sqrt n + The simplest and fastest estimator. Only takes into account the data size. -- cgit v1.2.1 From 51a1f46aa51079ce4fda5108aed4f71c17a28387 Mon Sep 17 00:00:00 2001 From: Ryan Levy Date: Sun, 5 May 2019 13:10:03 -0500 Subject: DOC: have notes in histogram_bin_edges match parameter style bins only accepts lowercase strings, but the notes are capitalized. --- numpy/lib/histograms.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'numpy/lib/histograms.py') diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index bd44d2732..ee9a3053c 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -555,14 +555,14 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): using the `ptp` of the data. The final bin count is obtained from ``np.round(np.ceil(range / h))``. - 'Auto' (maximum of the 'Sturges' and 'FD' estimators) + 'auto' (maximum of the 'sturges' and 'fd' estimators) A compromise to get a good value. For small datasets the Sturges value will usually be chosen, while larger datasets will usually default to FD. Avoids the overly conservative behaviour of FD and Sturges for small and large datasets respectively. Switchover point is usually :math:`a.size \approx 1000`. - 'FD' (Freedman Diaconis Estimator) + 'fd' (Freedman Diaconis Estimator) .. math:: h = 2 \frac{IQR}{n^{1/3}} The binwidth is proportional to the interquartile range (IQR) @@ -570,7 +570,7 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): conservative for small datasets, but is quite good for large datasets. The IQR is very robust to outliers. - 'Scott' + 'scott' .. math:: h = \sigma \sqrt[3]{\frac{24 * \sqrt{\pi}}{n}} The binwidth is proportional to the standard deviation of the @@ -580,14 +580,14 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): outliers. Values are very similar to the Freedman-Diaconis estimator in the absence of outliers. - 'Rice' + 'rice' .. math:: n_h = 2n^{1/3} The number of bins is only proportional to cube root of ``a.size``. It tends to overestimate the number of bins and it does not take into account data variability. - 'Sturges' + 'sturges' .. math:: n_h = \log _{2}n+1 The number of bins is the base 2 log of ``a.size``. This @@ -595,7 +595,7 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): larger, non-normal datasets. This is the default method in R's ``hist`` method. - 'Doane' + 'doane' .. math:: n_h = 1 + \log_{2}(n) + \log_{2}(1 + \frac{|g_1|}{\sigma_{g_1}}) @@ -607,7 +607,7 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): estimates for non-normal datasets. This estimator attempts to account for the skew of the data. - 'Sqrt' + 'sqrt' .. math:: n_h = \sqrt n The simplest and fastest estimator. Only takes into account the -- cgit v1.2.1 From f9c1502e7ace9b48f0256a77c560aae43763a1f2 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Mon, 20 May 2019 09:37:18 -0700 Subject: BUG: Increment stacklevel for warnings to account for NEP-18 overrides (#13589) * Increment stacklevel for warnings to account for NEP-18 overrides For NumPy functions that make use of `__array_function__`, the appropriate the stack level for warnings should generally be increased by 1 to account for the override function defined in numpy.core.overrides. Fixes GH-13329 * Update numpy/lib/type_check.py Co-Authored-By: Sebastian Berg --- numpy/lib/histograms.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'numpy/lib/histograms.py') diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index ee9a3053c..5bcedc7f4 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -148,7 +148,8 @@ def _hist_bin_stone(x, range): nbins_upper_bound = max(100, int(np.sqrt(n))) nbins = min(_range(1, nbins_upper_bound + 1), key=jhat) if nbins == nbins_upper_bound: - warnings.warn("The number of bins estimated may be suboptimal.", RuntimeWarning, stacklevel=2) + warnings.warn("The number of bins estimated may be suboptimal.", + RuntimeWarning, stacklevel=3) return ptp_x / nbins @@ -279,7 +280,7 @@ def _ravel_and_check_weights(a, weights): if a.dtype == np.bool_: warnings.warn("Converting input from {} to {} for compatibility." .format(a.dtype, np.uint8), - RuntimeWarning, stacklevel=2) + RuntimeWarning, stacklevel=3) a = a.astype(np.uint8) if weights is not None: @@ -888,7 +889,7 @@ def histogram(a, bins=10, range=None, normed=None, weights=None, warnings.warn( "The normed argument is ignored when density is provided. " "In future passing both will result in an error.", - DeprecationWarning, stacklevel=2) + DeprecationWarning, stacklevel=3) normed = None if density: @@ -904,7 +905,7 @@ def histogram(a, bins=10, range=None, normed=None, weights=None, "density=True will produce the same result anyway. " "The argument will be removed in a future version of " "numpy.", - np.VisibleDeprecationWarning, stacklevel=2) + np.VisibleDeprecationWarning, stacklevel=3) # this normalization is incorrect, but db = np.array(np.diff(bin_edges), float) @@ -915,7 +916,7 @@ def histogram(a, bins=10, range=None, normed=None, weights=None, warnings.warn( "Passing normed=False is deprecated, and has no effect. " "Consider passing the density argument instead.", - DeprecationWarning, stacklevel=2) + DeprecationWarning, stacklevel=3) return n, bin_edges -- cgit v1.2.1 From 080bf0064b64c3c95499473101c297c3d10e5348 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Tue, 11 Jun 2019 21:13:12 -0400 Subject: MAINT: fix histogram*d dispatchers fixes GH-13728 --- numpy/lib/histograms.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'numpy/lib/histograms.py') diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index 5bcedc7f4..478fbc783 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -3,6 +3,7 @@ Histogram-related functions """ from __future__ import division, absolute_import, print_function +import contextlib import functools import operator import warnings @@ -922,7 +923,13 @@ def histogram(a, bins=10, range=None, normed=None, weights=None, def _histogramdd_dispatcher(sample, bins=None, range=None, normed=None, weights=None, density=None): - return (sample, bins, weights) + if hasattr(sample, 'shape'): # same condition as used in histogramdd + yield sample + else: + yield from sample + with contextlib.supress(TypeError): + yield from bins + yield weights @array_function_dispatch(_histogramdd_dispatcher) -- cgit v1.2.1 From ebb0c5d3e4fc3835c1b71434845f03ae7bbaae0c Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Tue, 11 Jun 2019 21:41:38 -0400 Subject: MAINT: spelling --- numpy/lib/histograms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/histograms.py') diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py index 478fbc783..8474bd5d3 100644 --- a/numpy/lib/histograms.py +++ b/numpy/lib/histograms.py @@ -927,7 +927,7 @@ def _histogramdd_dispatcher(sample, bins=None, range=None, normed=None, yield sample else: yield from sample - with contextlib.supress(TypeError): + with contextlib.suppress(TypeError): yield from bins yield weights -- cgit v1.2.1