summaryrefslogtreecommitdiff
path: root/numpy/lib/histograms.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-06-02 09:34:26 -0700
committerSebastian Berg <sebastian@sipsolutions.net>2022-06-02 09:34:26 -0700
commit2215054472616df563faa4613734426c790d4217 (patch)
tree4163f6afddf6a3a24c34a267b78bcbbace1947b0 /numpy/lib/histograms.py
parentb84a53df9346a73fe8f6df0aaad8727f9bf56076 (diff)
downloadnumpy-2215054472616df563faa4613734426c790d4217.tar.gz
DEP: Remove `normed=` keyword argument from histogroms
The normed keyword argument has been deprecated for a long time. This removes it, replacing its position with the new density argument.
Diffstat (limited to 'numpy/lib/histograms.py')
-rw-r--r--numpy/lib/histograms.py77
1 files changed, 9 insertions, 68 deletions
diff --git a/numpy/lib/histograms.py b/numpy/lib/histograms.py
index 98182f1c4..f7feb2531 100644
--- a/numpy/lib/histograms.py
+++ b/numpy/lib/histograms.py
@@ -671,13 +671,12 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None):
def _histogram_dispatcher(
- a, bins=None, range=None, normed=None, weights=None, density=None):
+ a, bins=None, range=None, density=None, weights=None):
return (a, bins, weights)
@array_function_dispatch(_histogram_dispatcher)
-def histogram(a, bins=10, range=None, normed=None, weights=None,
- density=None):
+def histogram(a, bins=10, range=None, density=None, weights=None):
r"""
Compute the histogram of a dataset.
@@ -704,16 +703,6 @@ def histogram(a, bins=10, range=None, normed=None, weights=None,
computation as well. While bin width is computed to be optimal
based on the actual data within `range`, the bin count will fill
the entire range including portions containing no data.
- normed : bool, optional
-
- .. deprecated:: 1.6.0
-
- This is equivalent to the `density` argument, but produces incorrect
- results for unequal bin widths. It should not be used.
-
- .. versionchanged:: 1.15.0
- DeprecationWarnings are actually emitted.
-
weights : array_like, optional
An array of weights, of the same shape as `a`. Each value in
`a` only contributes its associated weight towards the bin count
@@ -728,8 +717,6 @@ def histogram(a, bins=10, range=None, normed=None, weights=None,
histogram values will not be equal to 1 unless bins of unity
width are chosen; it is not a probability *mass* function.
- Overrides the ``normed`` keyword if given.
-
Returns
-------
hist : array
@@ -891,46 +878,15 @@ def histogram(a, bins=10, range=None, normed=None, weights=None,
n = np.diff(cum_n)
- # density overrides the normed keyword
- if density is not None:
- if normed is not None:
- # 2018-06-13, numpy 1.15.0 (this was not noisily deprecated in 1.6)
- warnings.warn(
- "The normed argument is ignored when density is provided. "
- "In future passing both will result in an error.",
- DeprecationWarning, stacklevel=3)
- normed = None
-
if density:
db = np.array(np.diff(bin_edges), float)
return n/db/n.sum(), bin_edges
- elif normed:
- # 2018-06-13, numpy 1.15.0 (this was not noisily deprecated in 1.6)
- warnings.warn(
- "Passing `normed=True` on non-uniform bins has always been "
- "broken, and computes neither the probability density "
- "function nor the probability mass function. "
- "The result is only correct if the bins are uniform, when "
- "density=True will produce the same result anyway. "
- "The argument will be removed in a future version of "
- "numpy.",
- np.VisibleDeprecationWarning, stacklevel=3)
-
- # this normalization is incorrect, but
- db = np.array(np.diff(bin_edges), float)
- return n/(n*db).sum(), bin_edges
- else:
- if normed is not None:
- # 2018-06-13, numpy 1.15.0 (this was not noisily deprecated in 1.6)
- warnings.warn(
- "Passing normed=False is deprecated, and has no effect. "
- "Consider passing the density argument instead.",
- DeprecationWarning, stacklevel=3)
- return n, bin_edges
+
+ return n, bin_edges
-def _histogramdd_dispatcher(sample, bins=None, range=None, normed=None,
- weights=None, density=None):
+def _histogramdd_dispatcher(sample, bins=None, range=None, density=None,
+ weights=None):
if hasattr(sample, 'shape'): # same condition as used in histogramdd
yield sample
else:
@@ -941,8 +897,7 @@ def _histogramdd_dispatcher(sample, bins=None, range=None, normed=None,
@array_function_dispatch(_histogramdd_dispatcher)
-def histogramdd(sample, bins=10, range=None, normed=None, weights=None,
- density=None):
+def histogramdd(sample, bins=10, range=None, density=None, weights=None):
"""
Compute the multidimensional histogram of some data.
@@ -979,20 +934,16 @@ def histogramdd(sample, bins=10, range=None, normed=None, weights=None,
If False, the default, returns the number of samples in each bin.
If True, returns the probability *density* function at the bin,
``bin_count / sample_count / bin_volume``.
- normed : bool, optional
- An alias for the density argument that behaves identically. To avoid
- confusion with the broken normed argument to `histogram`, `density`
- should be preferred.
weights : (N,) array_like, optional
An array of values `w_i` weighing each sample `(x_i, y_i, z_i, ...)`.
- Weights are normalized to 1 if normed is True. If normed is False,
+ Weights are normalized to 1 if density is True. If density is False,
the values of the returned histogram are equal to the sum of the
weights belonging to the samples falling into each bin.
Returns
-------
H : ndarray
- The multidimensional histogram of sample x. See normed and weights
+ The multidimensional histogram of sample x. See density and weights
for the different possible semantics.
edges : list
A list of D arrays describing the bin edges for each dimension.
@@ -1104,16 +1055,6 @@ def histogramdd(sample, bins=10, range=None, normed=None, weights=None,
core = D*(slice(1, -1),)
hist = hist[core]
- # handle the aliasing normed argument
- if normed is None:
- if density is None:
- density = False
- elif density is None:
- # an explicit normed argument was passed, alias it to the new name
- density = normed
- else:
- raise TypeError("Cannot specify both 'normed' and 'density'")
-
if density:
# calculate the probability density function
s = hist.sum()