Passing DataFrame with `|>` to anonymous function changing size?

What I am doing is redirect the dataset through pipeline operator to show the 6 first lines. There is two difference versions below:

Version 1:
train_df_dropped = hcat(select(train_df, Not(:type)), df) first(train_df_dropped, 6)

Version 2:
train_df_dropped = hcat(select(train_df, Not(:type)), df) |> x -> first(x, 6)

I expected the second version similar to version 1 but it’s not. It’s convert my dataset from mxn to 6xn.

Edit: I found the problem with my code that I need the brackets around equation before redirect it to anonymous function. It seems |> operator has higher priority than =.

Here is the final code:
(train_df_dropped = hcat(select(train_df, Not(:type)), df)) |> x -> first(x, 6)

You already found the solution, but just for reference:

Assignment = indeed has lower precedence than |> . I think basically anything of the form

x = # something

will be understood as "first evaluate # something and assign the result to x.

1 Like