Skip to content

Commit

Permalink
Merge pull request JuliaData#213 from HarlanH/getset
Browse files Browse the repository at this point in the history
Switch to get/set methods
  • Loading branch information
johnmyleswhite committed Mar 21, 2013
2 parents 30849a5 + 421c254 commit 774bef0
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 247 deletions.
4 changes: 2 additions & 2 deletions demo/examples.jl
Expand Up @@ -81,7 +81,7 @@ dv = DataArray(1:3)
#
# To order to provide a very concise constructor, we've hacked in
# a very cute constructor for DataVector's using a trick involving
# their ref() method.
# their getindex() method.
#

dv = DataVector[1, 2, NA, 4]
Expand Down Expand Up @@ -425,7 +425,7 @@ df .== df
#
# abs, sign, acos, acosh, asin, asinh, atan, atan2, atanh, sin, sinh
# cos, cosh, tan, tanh, ceil, floor, round, trunc, signif, exp, log
# log10, log1p, log2, logb, sqrt
# log10, log1p, log2, exponent, sqrt
#
##############################################################################

Expand Down
4 changes: 2 additions & 2 deletions doc/sections/03_design_details.md
Expand Up @@ -139,7 +139,7 @@ In contrast to these normal-looking constructors, when some of the values in the

dv = DataVector[1, 2, NA, 4]

_Technical Note: This special type of constructor is defined by overloading the `ref()` function to apply to values of type `DataVector`.
_Technical Note: This special type of constructor is defined by overloading the `getindex()` function to apply to values of type `DataVector`.

# DataVector's with Special Types

Expand Down Expand Up @@ -444,7 +444,7 @@ The standard comparison operators work on `DataVector`'s:
* `log10`
* `log1p`
* `log2`
* `logb`
* `exponent`
* `sqrt`

Standard functions that apply to scalar values of type `Number` return `NA` when applied to `NA`:
Expand Down
2 changes: 1 addition & 1 deletion doc/sections/04_specification.md
Expand Up @@ -176,6 +176,6 @@ DataFrame's add two new indexer types:

These can only occur as (a) the only indexer or (b) in the second slot of a paired indexer

Anything that can be ref()'d can also be assign()'d
Anything that can be getindex()'d can also be setindex!()'d

Where do we allow Expr indexing?
14 changes: 7 additions & 7 deletions doc/sections/05_function_reference_guide.md
Expand Up @@ -109,14 +109,14 @@ are selected. Indexing along rows works like Matrix indexing. Indexing
along columns works like Matrix indexing with the addition of column
name access.

#### `ref(df::DataFrame, ind)` or `df[ind]`
#### `getindex(df::DataFrame, ind)` or `df[ind]`

Returns a subset of the columns of `df` as specified by `ind`, which
may be an `Int`, a `Range`, a `Vector{Int}`, `ByteString`, or
`Vector{ByteString}`. Columns are referenced, not copied. For a
single-element `ind`, the column by itself is returned.

#### `ref(df::DataFrame, irow, icol)` or `df[irow,icol]`
#### `getindex(df::DataFrame, irow, icol)` or `df[irow,icol]`

Returns a subset of `df` as specified by `irow` and `icol`. `irow` may
be an `Int`, a `Range`, or a `Vector{Int}`. `icol` may be an `Int`, a
Expand All @@ -138,7 +138,7 @@ See the Indexing section for these operations on column indexes.

The column names as an `Array{ByteString}`

#### `assign(df::DataFrame, newcol, colname)` or `df[colname] = newcol`
#### `setindex!(df::DataFrame, newcol, colname)` or `df[colname] = newcol`

Replace or add a new column with name `colname` and contents `newcol`.
Arrays are converted to DataVector's. Values are recycled to match the
Expand Down Expand Up @@ -224,8 +224,8 @@ Return a SubDataFrame with references to rows and columns of `df`.

Return a SubDataFrame with references to rows and columns of `df`.

#### `ref(sd::SubDataFrame, r, c)` or `sd[r,c]`
#### `ref(sd::SubDataFrame, c)` or `sd[c]`
#### `getindex(sd::SubDataFrame, r, c)` or `sd[r,c]`
#### `getindex(sd::SubDataFrame, c)` or `sd[c]`

Referencing should work the same as DataFrames.

Expand All @@ -241,7 +241,7 @@ columns with one or more names given in `cols`.

Methods to iterate over GroupedDataFrame groupings.

#### `ref(gd::GroupedDataFrame, idx)` or `gd[idx]`
#### `getindex(gd::GroupedDataFrame, idx)` or `gd[idx]`

Reference a particular grouping. Referencing returns a SubDataFrame.

Expand Down Expand Up @@ -344,7 +344,7 @@ Set names `nm` in `x`.

Replace names `from` with `to` in `x`.

#### `ref(x::Index, idx)` or `x[idx]`
#### `getindex(x::Index, idx)` or `x[idx]`

This does the mapping from name(s) to Indices (positions). `idx` may
be ByteString, Vector{ByteString}, Int, Vector{Int}, Range{Int},
Expand Down
14 changes: 7 additions & 7 deletions spec/FunctionReference.md
Expand Up @@ -109,14 +109,14 @@ are selected. Indexing along rows works like Matrix indexing. Indexing
along columns works like Matrix indexing with the addition of column
name access.

#### `ref(df::DataFrame, ind)` or `df[ind]`
#### `getindex(df::DataFrame, ind)` or `df[ind]`

Returns a subset of the columns of `df` as specified by `ind`, which
may be an `Int`, a `Range`, a `Vector{Int}`, `ByteString`, or
`Vector{ByteString}`. Columns are referenced, not copied. For a
single-element `ind`, the column by itself is returned.

#### `ref(df::DataFrame, irow, icol)` or `df[irow,icol]`
#### `getindex(df::DataFrame, irow, icol)` or `df[irow,icol]`

Returns a subset of `df` as specified by `irow` and `icol`. `irow` may
be an `Int`, a `Range`, or a `Vector{Int}`. `icol` may be an `Int`, a
Expand All @@ -138,7 +138,7 @@ See the Indexing section for these operations on column indexes.

The column names as an `Array{ByteString}`

#### `assign(df::DataFrame, newcol, colname)` or `df[colname] = newcol`
#### `setindex!(df::DataFrame, newcol, colname)` or `df[colname] = newcol`

Replace or add a new column with name `colname` and contents `newcol`.
Arrays are converted to DataVector's. Values are recycled to match the
Expand Down Expand Up @@ -224,8 +224,8 @@ Return a SubDataFrame with references to rows and columns of `df`.

Return a SubDataFrame with references to rows and columns of `df`.

#### `ref(sd::SubDataFrame, r, c)` or `sd[r,c]`
#### `ref(sd::SubDataFrame, c)` or `sd[c]`
#### `getindex(sd::SubDataFrame, r, c)` or `sd[r,c]`
#### `getindex(sd::SubDataFrame, c)` or `sd[c]`

Referencing should work the same as DataFrames.

Expand All @@ -241,7 +241,7 @@ columns with one or more names given in `cols`.

Methods to iterate over GroupedDataFrame groupings.

#### `ref(gd::GroupedDataFrame, idx)` or `gd[idx]`
#### `getindex(gd::GroupedDataFrame, idx)` or `gd[idx]`

Reference a particular grouping. Referencing returns a SubDataFrame.

Expand Down Expand Up @@ -344,7 +344,7 @@ Set names `nm` in `x`.

Replace names `from` with `to` in `x`.

#### `ref(x::Index, idx)` or `x[idx]`
#### `getindex(x::Index, idx)` or `x[idx]`

This does the mapping from name(s) to Indices (positions). `idx` may
be ByteString, Vector{ByteString}, Int, Vector{Int}, Range{Int},
Expand Down
6 changes: 6 additions & 0 deletions src/DataFrames.jl
@@ -1,5 +1,11 @@
require("Options")

# Note that the two calls to using Stats in this file are
# strictly required: one pulls the names into DataFrames
# for easy access within the module, whereas the other call
# pushes those names into Main.
using Stats

module DataFrames

##############################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/RDA.jl
Expand Up @@ -180,7 +180,7 @@ function namedobjects(io::IO, fl::Uint32, A::Bool, symtab::Array{RSymbol,1})
while uint8(fl) != 0xfe
## need to call RSymbol here b/c of symbol reference table
nm = RSymbol(io, readuint32(io, A), A, symtab).displayname
assign(res, readitem(io, A, symtab), nm)
setindex!(res, readitem(io, A, symtab), nm)
fl = readuint32(io, A)
end
res
Expand Down

0 comments on commit 774bef0

Please sign in to comment.