# \[DataFrames Question\]: Filter function parameter order

**URL:** <https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395>\
**Category:** Data\
**Tags:** question\
**Created:** [March 3, 2021, 10:50am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395 "2021-03-03T10:50:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![citron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/citron/32/22478_2.png) [@citron](https://discourse.julialang.org/u/citron)\
**Post date:** [March 3, 2021, 10:50am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395/1 "2021-03-03T10:50:10Z")

</div>

# Question:

This is not a technical question. Consider it esthetechnical. While all functions from the DataFrames module get a DataFrame as first parameter, why don’t “Filter” and “Map” get this treatment too ?  
Why  
`filter(function, df::AbstractDataFrame)`  
but not  
`filter(df::AbstractDataFrame, function)`  
?

# Dataset (if applicable): any

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 3, 2021, 11:28am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395/2 "2021-03-03T11:28:55Z")

</div>

That’s just the way `filter` works in general - DataFrame strives for consistency with Julia base where possible:

```julia
help?> filter
search: filter filter! fieldtype fieldtypes

  filter(f, a)

  Return a copy of collection a, removing elements for which f is false. The function f is passed one argument.

```

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 3, 2021, 11:49am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395/3 "2021-03-03T11:49:10Z")

</div>

Note that in the development version of DataFrames (to be released as 1.0), a new [`subset`](https://dataframes.juliadata.org/latest/lib/functions/#DataFrames.subset) function is provided which is more consistent with other DataFrames functions.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [March 5, 2021, 4:29am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395/4 "2021-03-05T04:29:03Z")

</div>

The `filter(df, f)` method is in [GitHub - xiaodaigh/DataConvenience.jl: Convenience functions missing in Julia](https://github.com/xiaodaigh/DataConvenience.jl)

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [March 5, 2021, 4:44am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395/5 "2021-03-05T04:44:37Z")

</div>

> [@nalimilan](#):
>
> Note that in the development version of DataFrames (to be released as 1.0), a new [`subset`](https://dataframes.juliadata.org/latest/lib/functions/#DataFrames.subset) function is provided which is more consistent with other DataFrames functions.

Very happy to see this.

---

<div class="post-metadata">

**Author:** ![haberdashPI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haberdashpi/32/26337_2.png) [@haberdashPI](https://discourse.julialang.org/u/haberdashPI)\
**Post date:** [March 5, 2021, 5:36am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395/6 "2021-03-05T05:36:49Z")

</div>

The `@where` macro from from [DataFramesMeta](https://github.com/JuliaData/DataFramesMeta.jl) has the “right” order, I find that to be relatively convenient.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [March 5, 2021, 7:29am UTC](https://discourse.julialang.org/t/dataframes-question-filter-function-parameter-order/56395/7 "2021-03-05T07:29:20Z")

</div>

Since no one’s mentioned it, just to expand that the reason Base functions that take in a function argument put that function argument first (see also `map`, `reduce`, `broadcast`, etc…) is so that you can use those functions with `do` blocks, like

```julia
filter(1:10) do x
    4 < x < 7
end

```

since the `do` block creates an anonymous function and then by convention passes it as the first argument to the function.
