Closed s-leroux closed 7 months ago
- OTOH, some use cases seem hard to express at first sight without explicit index selection. For example: "Calculate the average prices per month"
What about:
serie.select(
(fc.named("MONTH"), fc.month, "DATE"),
(fc.named("PRICE"), "CLOSE"),
).sort_by(
(fc.concat, "MONTH", "DATE"),
).group_by(
"MONTH",
(ag.avg, fc.named("AVG PRICE"), "PRICE")
)
Few comments:
group_by
clause/predicate, the aggregate function for the index defaults to fc.first
as it is hard-coded now: https://github.com/s-leroux/fin/blob/8352851a60c206fa6a8e7a3813bbf440ab952073/fin/seq/serie.pyx#L226select
and group_by
explicitly state the columns in the result series. But join operations work on the full series column set. What should be done for sort_by
? Should the behavior be consistent between all predicates, for example, saying the only select
can change the column set? It seems rather impracticable for group_by
, though.From c058cfb1523e734548d1479a90ad2f02f4406d50 and now on, I will experiment with removing the index
"special" column.
Some previously implicit things will have to now become explicit, like specifying the join column(s). This will cause problems with the operator version &
and |
.
... or we may make the index a "hidden" property of the serie to keep track of their order for operations that require implicit knowledge of that?
... or we may make the index a "hidden" property of the serie to keep track of their order for operations that require implicit knowledge of that?
I didn't manage to achieve something satisfying. Having a "hidden" index is not such a good idea as it rapidly become confusing for the user. Hard coding the index
as columns[0]
was not very convincing either.
There is no obvious way to specify the aggregate function for the index.
I wonder if adding implicitly the index in
select
/group_by
isn't an error. Maybe we can make the index reference mandatory. Would it be desirable to check that the index values are sorted in ascending order?Working on that in https://github.com/s-leroux/fin/tree/exp/make-index-selection-explicit
Originally posted by @s-leroux in https://github.com/s-leroux/fin/issues/30#issuecomment-2043759707
Other things to consider:
sort
predicate to change the index.