Indexing
General rules
The following rules explain target functionality of how getindex
, setindex!
, and view
are intended to work with DataFrame
, SubDataFrame
and DataFrameRow
objects.
The rules for a valid type of index into a column are the following:
- a value, later denoted as
col
:- a
Symbol
; - an
Integer
that is notBool
;
- a
- a vector, later denoted as
cols
:- a vector of
Symbol
(does not have to be a subtype ofAbstractVector{Symbol}
); - a vector of
Integer
other thanBool
(does not have to be a subtype ofAbstractVector{<:Integer}
); - a vector of
Bool
that has to be a subtype ofAbstractVector{Bool}
. - a colon.
- a vector of
The rules for a valid type of index into a row are the following:
- a value, later denoted as
row
:- an
Integer
that is notBool
;
- an
- a vector, later denoted as
rows
:- a vector of
Integer
other thanBool
(does not have to be a subtype ofAbstractVector{<:Integer}
); - a vector of
Bool
that has to be a subtype ofAbstractVector{Bool}
; - a colon.
- a vector of
In the descriptions below df
represents a DataFrame
, sdf
is a SubDataFrame
and dfr
is a DataFrameRow
.
getindex
The following list specifies return types of getindex
operations depending on argument types.
In all operations copying vectors is avoided where possible. If it is performed a description explicitly mentions that the data is copied.
For performance reasons, accessing, via getindex
or view
, a single row
and multiple cols
of a DataFrame
, a SubDataFrame
or a DataFrameRow
always returns a DataFrameRow
(which is a view-like type).
DataFrame
:
df[col]
-> the vector contained in columncol
;df[cols]
-> a freshly allocatedDataFrame
containing the vectors contained in columnscols
;df[row, col]
-> the value contained in rowrow
of columncol
, the same asdf[col][row]
;df[row, cols]
-> aDataFrameRow
with parentdf
ifcols
is a colon anddf[cols]
otherwise;df[rows, col]
-> a copy of the vectordf[col]
with only the entries corresponding torows
selected, the same asdf[col][rows]
;df[rows, cols]
-> aDataFrame
containing copies of columnscols
with only the entries corresponding torows
selected.@view df[col]
-> the vector contained in columncol
(this is equivalent todf[col]
);@view df[cols]
-> aSubDataFrame
with parentdf
ifcols
is a colon anddf[cols]
otherwise;@view df[row, col]
-> a0
-dimensional view intodf[col]
, the same asview(df[col], row)
;@view df[row, cols]
-> aDataFrameRow
with parentdf
ifcols
is a colon anddf[cols]
otherwise;@view df[rows, col]
-> a view intodf[col]
withrows
selected, the same asview(df[col], rows)
;@view df[rows, cols]
-> aSubDataFrame
withrows
selected with parentdf
ifcols
is a colon anddf[cols]
otherwise.
SubDataFrame
:
sdf[col]
-> a view of the vector contained in columncol
ofparent(sdf)
withDataFrames.rows(sdf)
as a selector;sdf[cols]
-> aSubDataFrame
, with parentparent(sdf)
ifcols
is a colon andparent(sdf)[cols]
otherwise;sdf[row, col]
-> a value contained in rowrow
of columncol
;sdf[row, cols]
-> aDataFrameRow
with parentparent(sdf)
ifcols
is a colon andparent(sdf)[cols]
otherwise;sdf[rows, col]
-> a copy of a vectorsdf[col]
with only rowsrows
selected;sdf[rows, cols]
-> aDataFrame
containing columnscols
anddf[rows, col]
as a vector in eachcol
incols
.@view sdf[col]
-> a view of vector contained in columncol
ofparent(sdf)
withDataFrames.rows(sdf)
as selector;@view sdf[cols]
-> aSubDataFrame
with parentparent(sdf)
ifcols
is a colon andparent(sdf)[cols]
otherwise;@view sdf[row, col]
-> translates toview(sdf[col], row)
(a0
-dimensional view intodf[col]
);@view sdf[row, cols]
-> aDataFrameRow
with parentparent(sdf)
ifcols
is a colon andparent(sdf)[cols]
otherwise;@view sdf[rows, col]
-> translates toview(sdf[col], rows)
(a standard view intosdf[col]
vector);@view sdf[rows, cols]
-> aSubDataFrame
with parentparent(sdf)
ifcols
is a colon andsdf[cols]
otherwise.
DataFrameRow
:
dfr[col]
-> the value contained in columncol
ofdfr
;dfr[cols]
-> aDataFrameRow
with parentparent(dfr)
ifcols
is a colon andparent(dfr)[cols]
otherwise;@view dfr[col]
-> a0
-dimensional view intoparent(dfr)[DataFrames.row(dfr), col]
;@view dfr[cols]
-> aDataFrameRow
with parentparent(dfr)
ifcols
is a colon andparent(dfr)[cols]
otherwise;
setindex!
Under construction