`last` aggregate returns the group's highest-index row, not its most recently updated row
Bug Report
Steps to Reproduce:
# pip install perspective-python==5.9.2
from perspective import Server
client = Server().new_local_client()
t = client.table({"k": [1, 2], "g": ["a", "a"], "p": [10.0, 20.0]}, index="k")
t.update([{"k": 1, "p": 15.0}]) # k=1 is now the most recently updated row
for agg in ["last", "last by index"]:
view = t.view(group_by=["g"], columns=["p"], aggregates={"p": agg})
print(agg, view.to_columns()["p"])
Expected Result:
last [15.0, 15.0]
last by index [20.0, 20.0]
The aggregates docs define last as "Value from the group's most recently updated row" (https://perspective-dev.github.io/guide/explanation/view/config/grouping_and_pivots.html).
Actual Result:
last [20.0, 20.0]
last by index [20.0, 20.0]
last matched last by index in every case we tried, including other column types, a string index, CSV, Arrow and column-dict updates, and a view created before the update. If index order is the intended meaning, then the docs sentence is what needs changing.
Environment:
- perspective-python 5.9.2 (newest on PyPI); same result on 5.9.1 and 5.8.0.
- CPython 3.14.3, pip 26.0
- macOS arm64 (Darwin 27.2.0)
Additional Context:
AI agents testing the documented Python workflows found this, and this report was drafted with their help; the reproduction was run on synthetic data.
Apologies, this is not a bug, but the aggregate description in the docs are very bad (the use the terms "earliest" and "latest" but they mean with respect to index). last/last by index do not return the most recently updated rows by insertion order, they are actually just different strategies for calculating rollup rows (your example only has a total rollup because it is one group_by column).
Perspective cannot have an aggregate that works like this - insertion order is not tracked by the engine independently, rather the index is what the engine uses to track insertion order unless you override it - in your example you have an explicit index="k" and rewrite k=1 in the past relative to the index order for both aggregates.
If you want the last by insertion order independent of index, it needs to be in an explicit column like timestamp, then you can use the max_by aggregate:
view = t.view(group_by=["g"], columns=["p"], aggregates={"p":["max_by",["timestamp"]]})