8000 Merge pull request #14045 from charris/backport-13757 · numpy/numpy@ca0ef6f · GitHub
[go: up one dir, main page]

Skip to content

Commit ca0ef6f

Browse files
authored
Merge pull request #14045 from charris/backport-13757
MAINT: fix histogram*d dispatchers
2 parents 4722baf + d4861f2 commit ca0ef6f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

numpy/lib/histograms.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
from __future__ import division, absolute_import, print_function
55

6+
import contextlib
67
import functools
78
import operator
89
import warnings
@@ -918,7 +919,15 @@ def histogram(a, bins=10, range=None, normed=None, weights=None,
918919

919920
def _histogramdd_dispatcher(sample, bins=None, range=None, normed=None,
920921
weights=None, density=None):
921-
return (sample, bins, weights)
922+
if hasattr(sample, 'shape'): # same condition as used in histogramdd
923+
yield sample
924+
else:
925+
for s in sample:
926+
yield s
927+
with contextlib.suppress(TypeError):
928+
for b in bins:
929+
yield b
930+
yield weights
922931

923932

924933
@array_function_dispatch(_histogramdd_dispatcher)

numpy/lib/twodim_base.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,21 @@ def vander(x, N=None, increasing=False):
565565

566566
def _histogram2d_dispatcher(x, y, bins=None, range=None, normed=None,
567567
weights=None, density=None):
568-
return (x, y, bins, weights)
568+
yield x
569+
yield y
570+
571+
# This terrible logic is adapted from the checks in histogram2d
572+
try:
573+
N = len(bins)
574+
except TypeError:
575+
N = 1
576+
if N != 1 and N != 2:
577+
for b in bins:
578+
yield b
579+
else:
580+
yield bins
581+
582+
yield weights
569583

570584

571585
@array_function_dispatch(_histogram2d_dispatcher)

0 commit comments

Comments
 (0)
0