# \[RFC, ANN\] WindowMap.jl

**URL:** <https://discourse.julialang.org/t/rfc-ann-windowmap-jl/38441>\
**Category:** Package Announcements\
**Created:** [April 29, 2020, 7:02pm UTC](https://discourse.julialang.org/t/rfc-ann-windowmap-jl/38441 "2020-04-29T19:02:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [April 29, 2020, 7:02pm UTC](https://discourse.julialang.org/t/rfc-ann-windowmap-jl/38441/1 "2020-04-29T19:02:36Z")

</div>

Regularly I need to apply a function to a series of `y[i]` in a windowed (rolling) way, where the window is defined by _values of another series_ `x[i]` instead of the _indices_ `i` themselves. E.g. `x` represents timestamps, `y` are some measurements, and the target result is a rolling average of measurements wrt time. I could not find any existing library that can perform this kind of mapping, neither in Julia nor in Python. For quite some time I wrote ad-hoc implementations with different hardcoded assumptions in different projects of mine, but recently I decided to format this as a reasonably reusable package.

The package can be installed from [https://github.com/aplavin/WindowMap.jl](https://github.com/aplavin/WindowMap.jl), and there is a jupyter notebook with simple usage examples: [https://github.com/aplavin/WindowMap.jl/blob/master/examples.ipynb](https://github.com/aplavin/WindowMap.jl/blob/master/examples.ipynb). For now it is not general enough for my usage: only univariate and bivariate applications are supported, and in the bivariate case the window can only be a product of two univariate windows; I’m planning to extend the package in this direction.

[https://github.com/aplavin/WindowMap.jl](https://github.com/aplavin/WindowMap.jl)

As I’m not experienced in writing general and reusable Julia code and packages, **I would be really thankful for any comments and suggestions regarding the overall design** of this package. The whole source code is only one file with 120 lines now: [https://github.com/aplavin/WindowMap.jl/blob/master/src/WindowMap.jl](https://github.com/aplavin/WindowMap.jl/blob/master/src/WindowMap.jl). I’m also curious of how you think performance could be improved while keeping the generality.

---

<div class="post-metadata">

**Author:** ![robsmith11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robsmith11/32/29641_2.png) [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Post date:** [April 30, 2020, 2:53am UTC](https://discourse.julialang.org/t/rfc-ann-windowmap-jl/38441/2 "2020-04-30T02:53:57Z")

</div>

Looks nice. I took a brief look at the code, but it wasn’t obvious to me: what happens to points that fall at a boundary between windows? Are they not included in any window? Also, is it possible for windows to overlap?

Another approach that I find useful for time series: [Window join | Reference | kdb+ and q documentation - Kdb+ and q documentation](https://code.kx.com/q/ref/wj/)

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [April 30, 2020, 1:45pm UTC](https://discourse.julialang.org/t/rfc-ann-windowmap-jl/38441/3 "2020-04-30T13:45:42Z")

</div>

Yes, if any point falls outside a window it is not included anywhere. But the main usecase, as illustrated in the examples, has highly overlapping windows: the step to shift the window is significantly smaller than the window width. I mainly use it for plotting, and in this scenario only steps much smaller than the window width make sense.

> Another approach that I find useful for time series: [Window join | Reference | kdb+ and q documentation - Kdb+ and q documentation](https://code.kx.com/q/ref/wj/)

Oh, that’s quite an obscure syntax 🙂 Looks like that function solves a different problem involving joining two tables, but maybe I misunderstood it.
