Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison of a dataframe and a number #1281

Closed
jannefiluren opened this issue Nov 21, 2017 · 3 comments
Closed

Comparison of a dataframe and a number #1281

jannefiluren opened this issue Nov 21, 2017 · 3 comments

Comments

@jannefiluren
Copy link

I want to know if 2 is within a subset of my dataframe.

df = DataFrame(a = [1,1], b=[2,2], c=[3,3])

# This doesn´t give the right answer, it returns false since it compares a dataframe to a number (I guess)

df[:,2:3] .== 2 

# This works as I want to, returns an array of true/false

convert(Array, df[:,2:3]) .== 2

To me, the result of the first operation seems like something people might make mistakes with without noticing it. And the second solution is a bit cumbersome. Should this behaviour be changed?

@nalimilan
Copy link
Member

As I noted on Slack: Sounds like a bug. df[:,2:3] .== 2 should either throw an error or return a data frame of the same shape as the original but with Bool columns. Maybe it already behaves differently on Julia 0.7, but I get an error when trying to load DataFrames right now.

@Nosferican
Copy link
Contributor

On Julia 0.7 is the same behavior. However, at least in my pipelines for StatsModels dataframes should always be converted to arrays in order to have Array like behavior. For a discussion on enabling Array behavior for AbstractDataFrames see #583.

@nalimilan
Copy link
Member

Fixed in Julia 1.0:

julia> df = DataFrame(a = [1,1], b=[2,2], c=[3,3]);
julia> df[:,2:3] .== 2 
ERROR: MethodError: no method matching iterate(::DataFrame)

See also #1513.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants