[Bug]: Weighted ApproximateQuantiles depends on the scale of the weights
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
The bug is in ApproximateQuantilesCombineFn.extract_output in the Python SDK's apache_beam/transforms/stats.py, where the offset = (total_weight - 1) / (num_quantiles - 1) term is used for weighted input. Read the docstring example and stats_test.py first, then check that weighted output stays the same when all weights are scaled. Linked PR #41560 is already open against this, so review or extend that PR instead of starting a parallel fix.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
What happened?
With weighted=True, ApproximateQuantiles gives different quantiles when every weight is multiplied by the same number, which shouldn't change a weighted quantile. Small weights give quantiles that are all the minimum:
import apache_beam as beam
from apache_beam.transforms.stats import ApproximateQuantiles
with beam.Pipeline() as p:
for w in (1, 0.5, 0.01, 0.001):
_ = (
p | f'Create {w}' >> beam.Create([(i, w) for i in range(101)])
| f'Quantiles {w}' >> ApproximateQuantiles.Globally(5, weighted=True)
| f'Print {w}' >> beam.Map(print))
# w=1 -> [0, 25, 50, 75, 100]
# w=0.5 -> [0, 24, 50, 75, 100]
# w=0.01 -> [0, 0, 25, 50, 100]
# w=0.001 -> [0, 0, 0, 0, 100]
The weighted example in the ApproximateQuantiles docstring ([(i, 1 if i<10 else 1e-5) for i in range(101)], documented output [0, 2, 5, 7, 100]) gives [0, 2, 4, 7, 100] on master. It gives the documented output only when the weights are multiplied by 1000.
ApproximateQuantilesCombineFn.extract_output uses offset = (total_weight - 1) / (num_quantiles - 1) in both cases. The - 1 turns an element count into the index of the last element, which is right without weights, but with weights it subtracts one unit of weight, so the targets move with the scale. With offset = step for the weighted case, the k-th quantile is the first element whose cumulative weight exceeds k * total_weight / (num_quantiles - 1). That gives [0, 25, 50, 75, 100] for every scale above and the documented docstring output, and the existing tests in stats_test.py still pass. I have a PR ready.
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components
- Component: Python SDK
- Vorherrschende Sprache
- Java
- Sterne
- 8.7k
- Forks
- 4.8k
- Ø Merge
- 3 T. 16 Std.
- Gemergte PRs (30 T.)
- 445
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus apache/beam
-
awaiting triage java new feature P2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug]: [Python] BigTableEnrichmentHandler coerces None lookup keys to literal b'None' and formats blank key name on KeyErrorEvtl. vergeben @shikhabhadoria hat das vor 6 Tagen übernommen. Offenio P2 python
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
apache/beam#41346 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Release notes links wrongEvtl. vergeben @schizophrenicmaniac hat das vor 20 Tagen übernommen. Offenbug P3
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 67/100
apache/beam#41197 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
apache/beam#39624 · 2 Reaktionen ·
Maintainer antworten meist innerhalb von 2 Tagen
-
[Bug]: PubsubIO used in batch incorrect batch cutoff sizeEvtl. vergeben @1fanwang hat das vor 98 Tagen übernommen. Offenbug io P3 pinned pubsub
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
apache/beam#28011 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
Ähnliche Issues
-
effort/l priority/p1 risk/high triage/core
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
iflytek/skillhub#1188 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
testng-team/testng#3675 ·
Maintainer antworten meist innerhalb von 1 Tag
-
design
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
OpenLiberty/liberty-tools-intellij#1869 ·
Maintainer antworten meist innerhalb von 1 Tag
-
`ovsx verify` fails for a version older than the 100 newest of an extensionEvtl. vergeben @trivikr hat das heute übernommen. Offencli
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 81/100
eclipse-openvsx/openvsx#2482 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
Maintainer antworten meist innerhalb von 1 Tag