diff --git a/docs/src/standalonequerycommands.md b/docs/src/standalonequerycommands.md index cd56e5c7..4f3551cd 100644 --- a/docs/src/standalonequerycommands.md +++ b/docs/src/standalonequerycommands.md @@ -433,18 +433,18 @@ println(q) │ 2 │ 3 │ 5 │ ``` -## The `@dissallowna` command +## The `@disallowna` command -The `@dissallowna` command has the form `source |> @dissallowna(columns...)`. `source` can be any source that can be queried and that has a table structure. If `@dissallowna()` is called without any arguments, it will check that there are no missing `NA` values in any column in any row of the input table and convert the element type of each column to one that cannot hold missing values. Alternatively one can pass a list of column names to `@dissallowna`, in which case it will only check for `NA` values in those columns, and only convert those columns to a type that cannot hold missing values. +The `@disallowna` command has the form `source |> @disallowna(columns...)`. `source` can be any source that can be queried and that has a table structure. If `@disallowna()` is called without any arguments, it will check that there are no missing `NA` values in any column in any row of the input table and convert the element type of each column to one that cannot hold missing values. Alternatively one can pass a list of column names to `@disallowna`, in which case it will only check for `NA` values in those columns, and only convert those columns to a type that cannot hold missing values. -Our first example uses the simple version of `@dissallowna()` that makes sure there are no missing values anywhere in the table. Note how the column type for column `a` is changed to `Int64` in this example, i.e. an element type that does not support missing values: +Our first example uses the simple version of `@disallowna()` that makes sure there are no missing values anywhere in the table. Note how the column type for column `a` is changed to `Int64` in this example, i.e. an element type that does not support missing values: ```jldoctest using Query, DataFrames df = DataFrame(a=[1,missing,3], b=[4,5,6]) -q = df |> @filter(!isna(_.a)) |> @dissallowna() |> DataFrame +q = df |> @filter(!isna(_.a)) |> @disallowna() |> DataFrame println(q) @@ -465,7 +465,7 @@ using Query, DataFrames df = DataFrame(a=[1,2,missing], b=[4,missing,5]) -q = df |> @filter(!isna(_.b)) |> @dissallowna(:b) |> DataFrame +q = df |> @filter(!isna(_.b)) |> @disallowna(:b) |> DataFrame println(q) diff --git a/src/Query.jl b/src/Query.jl index 921b4e3c..22ef671a 100644 --- a/src/Query.jl +++ b/src/Query.jl @@ -10,7 +10,7 @@ export @from, @query, @count, Grouping, key export @map, @filter, @groupby, @orderby, @orderby_descending, @unique, @thenby, @thenby_descending, @groupjoin, @join, @mapmany, @take, @drop -export @select, @rename, @mutate, @dissallowna, @dropna, @replacena +export @select, @rename, @mutate, @disallowna, @dropna, @replacena export isna, NA diff --git a/src/table_query_macros.jl b/src/table_query_macros.jl index c1d6df6e..48fce66d 100644 --- a/src/table_query_macros.jl +++ b/src/table_query_macros.jl @@ -193,20 +193,20 @@ our_get(x::DataValue) = get(x) our_get(x, y) = x our_get(x::DataValue, y) = get(x, y) -macro dissallowna() +macro disallowna() return :( Query.@map(map(our_get, _)) ) end -macro dissallowna(columns...) +macro disallowna(columns...) return :( Query.@mutate( $( ( :( $(columns[i].value) = our_get(_.$(columns[i].value)) ) for i=1:length(columns) )... ) ) ) end macro dropna() - return :( i-> i |> Query.@filter(!any(isna, _)) |> Query.@dissallowna() ) + return :( i-> i |> Query.@filter(!any(isna, _)) |> Query.@disallowna() ) end macro dropna(columns...) - return :( i-> i |> Query.@filter(!any(($((:(isna(_.$(columns[i].value))) for i in 1:length(columns) )...),))) |> Query.@dissallowna($(columns...)) ) + return :( i-> i |> Query.@filter(!any(($((:(isna(_.$(columns[i].value))) for i in 1:length(columns) )...),))) |> Query.@disallowna($(columns...)) ) end macro replacena(arg, args...) diff --git a/test/test_macros.jl b/test/test_macros.jl index 022351f2..1a6b4aa0 100644 --- a/test/test_macros.jl +++ b/test/test_macros.jl @@ -76,12 +76,12 @@ end @test df |> @replacena(:a=>2, :b=>8) |> collect == [(a=1,b=1.), (a=2, b=2.), (a=3, b=3.)] end -@testset "@dissallowna" begin +@testset "@disallowna" begin df = DataFrame(a=[1,missing,3], b=[1.,2.,3.]) - @test_throws DataValueException df |> @dissallowna() |> collect - @test df |> @filter(!any(isna, _)) |> @dissallowna() |> collect == [(a=1,b=1.), (a=3, b=3.)] - @test_throws DataValueException df |> @dissallowna(:a) |> collect - @test df |> @dissallowna(:b) |> collect == [(a=DataValue(1),b=1.), (a=DataValue{Int}(),b=2.),(a=DataValue(3), b=3.)] + @test_throws DataValueException df |> @disallowna() |> collect + @test df |> @filter(!any(isna, _)) |> @disallowna() |> collect == [(a=1,b=1.), (a=3, b=3.)] + @test_throws DataValueException df |> @disallowna(:a) |> collect + @test df |> @disallowna(:b) |> collect == [(a=DataValue(1),b=1.), (a=DataValue{Int}(),b=2.),(a=DataValue(3), b=3.)] end