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

rbind revision #197

Merged
merged 5 commits into from
Feb 17, 2013
Merged

rbind revision #197

merged 5 commits into from
Feb 17, 2013

Conversation

tshort
Copy link
Contributor

@tshort tshort commented Feb 17, 2013

Addresses issues #180 and #44.

I thought this was better as a pull request because it hits a few different things that may need feedback. Here are a few items of note:

promote_rule{T}(::Type{T}, ::Type{NAtype} ) = T
  • Because of this promote_rule, we now get warnings (see below). What is the promote_rule for AbstractDataArrays used for? I don't see something equivalent for AbstractArrays.

Here are some examples:

julia> using DataFrames
Warning: ignoring conflicting import of Stats.quantile into DataFrames
Warning: New definition promote_rule(Type{AbstractDataArray{T,N}},Type{T}) is ambiguous with promote_rule(Type{T},Type{NAtype}) at /home/tshort/.julia/DataFrames/src/natype.jl:32.
         Make sure promote_rule(Type{AbstractDataArray{T,N}},Type{NAtype}) is defined first.
Warning: New definition promote_rule(Type{AbstractDataArray{S,N}},Type{T}) is ambiguous with promote_rule(Type{T},Type{NAtype}) at /home/tshort/.julia/DataFrames/src/natype.jl:32.
         Make sure promote_rule(Type{AbstractDataArray{S,N}},Type{NAtype}) is defined first.

julia> d1 = @DataFrame(x => NA, y => 1)
1x2 DataFrame:
         x y
[1,]    NA 1


julia> rbind(d1,d1)
2x2 DataFrame:
         x y
[1,]    NA 1
[2,]    NA 1


julia> d1 = DataFrame({[1:3], LETTERS[1:3]}) # arrays
3x2 DataFrame:
        x1  x2
[1,]     1 "A"
[2,]     2 "B"
[3,]     3 "C"


julia> d2 = @DataFrame(x1 => [5:6], y1 => letters[5:6])
2x2 DataFrame:
        x1  y1
[1,]     5 "e"
[2,]     6 "f"


julia> rbind(d1,d1)
6x2 DataFrame:
        x1  x2
[1,]     1 "A"
[2,]     2 "B"
[3,]     3 "C"
[4,]     1 "A"
[5,]     2 "B"
[6,]     3 "C"


julia> rbind(d1,d2)
5x3 DataFrame:
        x1  x2  y1
[1,]     1 "A"  NA
[2,]     2 "B"  NA
[3,]     3 "C"  NA
[4,]     5  NA "e"
[5,]     6  NA "f"


julia> rbind(d2,d1)
5x3 DataFrame:
        x1  y1  x2
[1,]     5 "e"  NA
[2,]     6 "f"  NA
[3,]     1  NA "A"
[4,]     2  NA "B"
[5,]     3  NA "C"


julia> rbind(d2[[2]],d1)
5x3 DataFrame:
         y1 x1  x2
[1,]    "e" NA  NA
[2,]    "f" NA  NA
[3,]     NA  1 "A"
[4,]     NA  2 "B"
[5,]     NA  3 "C"


julia> rbind(stack_df(d1, ["x1","x2"]),d2)
8x4 DataFrame:
        variable value x1  y1
[1,]        "x1"     1 NA  NA
[2,]        "x1"     2 NA  NA
[3,]        "x1"     3 NA  NA
[4,]        "x2"   "A" NA  NA
[5,]        "x2"   "B" NA  NA
[6,]        "x2"   "C" NA  NA
[7,]          NA    NA  5 "e"
[8,]          NA    NA  6 "f"


julia> rbind(stack_df(d1, ["x1","x2"]),d2) | dump
DataFrame  8 observations of 4 variables
  variable: DataArray{Union(ASCIIString,UTF8String),1}(8) ["x1", "x1", "x1", "x2"]
  value: DataArray{Any,1}(8) {1, 2, 3, "A"}
  x1: DataArray{Int64,1}(8) [NA, NA, NA, NA]
  y1: DataArray{ASCIIString,1}(8) [NA, NA, NA, NA]

@johnmyleswhite
Copy link
Contributor

I won't have time to ruminate on this until next Saturday. If it doesn't break the tests, I would say to go ahead and merge it, but to leave it open so that we can come back and debate things later.

tshort added a commit that referenced this pull request Feb 17, 2013
@tshort tshort merged commit b3ca8d4 into master Feb 17, 2013
@tshort tshort deleted the rbind branch February 17, 2013 20:52
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

Successfully merging this pull request may close these issues.

3 participants