opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
opyn::DataFrame Class Referencefinal

Represents a sequence of Series with optional associated metadata. More...

#include <data_frame.h>

Public Types

using value_type = Series
 
using size_type = size_t
 
using const_reference = const value_type &
 
using const_iterator = std::vector< Series >::const_iterator
 

Public Member Functions

 DataFrame ()=default
 Constructs an empty DataFrame.
 
 DataFrame (std::vector< std::string > column_names, std::vector< std::vector< double > > column_data, std::unordered_map< std::string, std::string > attrs={})
 
 DataFrame (std::vector< Series > series, std::unordered_map< std::string, std::string > attrs={})
 Constructs a DataFrame with the given series.
 
bool operator== (const DataFrame &) const
 
std::vector< std::string > columns () const
 Returns this DataFrame's column labels.
 
std::tuple< size_t, size_t > shape () const
 Returns the shape (rows, columns) of this DataFrame.
 
size_t height () const
 Returns the number of rows in *this.
 
size_t width () const
 Returns the number of Series (columns) in *this. Equivalent to size().
 
std::unordered_map< std::string, std::string > attrs () const
 Returns this DataFrame's metadata (e.g. header key-values).
 
void set_attrs (std::unordered_map< std::string, std::string > new_attrs)
 Sets the attrs of this DataFrame to new_attrs.
 
bool has_attr (const std::string &key) const
 Returns true if *this has a metadata entry with a key of key.
 
std::optional< std::string > get_attr (const std::string &key) const
 
const_reference operator[] (std::string_view name) const
 
const_reference operator[] (size_type pos) const
 Returns a reference to the nth series at pos in *this (by-column).
 
size_type size () const
 Returns the number of Series (columns) in *this.
 
bool empty () const
 Returns true if *this contains no Series, false otherwise.
 
const_iterator begin () const
 Returns an iterator to the first Series of *this.
 
const_iterator end () const
 Returns an iterator past the last Series of *this.
 
const_iterator find (std::string_view name) const
 
DataFrame with_series (Series series) const
 

Detailed Description

Represents a sequence of Series with optional associated metadata.

Member Typedef Documentation

◆ const_iterator

using opyn::DataFrame::const_iterator = std::vector<Series>::const_iterator

◆ const_reference

◆ size_type

◆ value_type

Constructor & Destructor Documentation

◆ DataFrame() [1/3]

opyn::DataFrame::DataFrame ( )
default

Constructs an empty DataFrame.

◆ DataFrame() [2/3]

opyn::DataFrame::DataFrame ( std::vector< std::string >  column_names,
std::vector< std::vector< double > >  column_data,
std::unordered_map< std::string, std::string >  attrs = {} 
)
explicit

Constructs a DataFrame with the given column names and data.

Throws an exception if column_names.size() != column_data.size() or any entries in column_data have a different size.

◆ DataFrame() [3/3]

opyn::DataFrame::DataFrame ( std::vector< Series series,
std::unordered_map< std::string, std::string >  attrs = {} 
)
explicit

Constructs a DataFrame with the given series.

Member Function Documentation

◆ attrs()

std::unordered_map< std::string, std::string > opyn::DataFrame::attrs ( ) const

Returns this DataFrame's metadata (e.g. header key-values).

◆ begin()

const_iterator opyn::DataFrame::begin ( ) const
inline

Returns an iterator to the first Series of *this.

◆ columns()

std::vector< std::string > opyn::DataFrame::columns ( ) const

Returns this DataFrame's column labels.

◆ empty()

bool opyn::DataFrame::empty ( ) const
inline

Returns true if *this contains no Series, false otherwise.

◆ end()

const_iterator opyn::DataFrame::end ( ) const
inline

Returns an iterator past the last Series of *this.

◆ find()

const_iterator opyn::DataFrame::find ( std::string_view  name) const

Returns an iterator to the Series in *this that has the name name.

If no such Series is found, end() is returned.

◆ get_attr()

std::optional< std::string > opyn::DataFrame::get_attr ( const std::string &  key) const

Returns the value of the metadata entry with key key, or std::nullopt if the metadata contains no such entry.

◆ has_attr()

bool opyn::DataFrame::has_attr ( const std::string &  key) const

Returns true if *this has a metadata entry with a key of key.

◆ height()

size_t opyn::DataFrame::height ( ) const

Returns the number of rows in *this.

◆ operator==()

bool opyn::DataFrame::operator== ( const DataFrame ) const

Returns true all members of lhs compare equivalent to rhs.

Note: This operator confirms to IEEE 754 and C++'s regular type invariants, which means identity checks are non-reflexive for special values. Therefore, if either lhs or rhs contains NaN values, this operator will return false.

◆ operator[]() [1/2]

const_reference opyn::DataFrame::operator[] ( size_type  pos) const
inline

Returns a reference to the nth series at pos in *this (by-column).

◆ operator[]() [2/2]

const_reference opyn::DataFrame::operator[] ( std::string_view  name) const

Returns the Series in *this that has the name name.

Throws a std::exception if name cannot be found.

◆ set_attrs()

void opyn::DataFrame::set_attrs ( std::unordered_map< std::string, std::string >  new_attrs)

Sets the attrs of this DataFrame to new_attrs.

◆ shape()

std::tuple< size_t, size_t > opyn::DataFrame::shape ( ) const

Returns the shape (rows, columns) of this DataFrame.

◆ size()

size_type opyn::DataFrame::size ( ) const
inline

Returns the number of Series (columns) in *this.

◆ width()

size_t opyn::DataFrame::width ( ) const

Returns the number of Series (columns) in *this. Equivalent to size().

◆ with_series()

DataFrame opyn::DataFrame::with_series ( Series  series) const

Returns a new DataFrame with series merged into it.

  • The name of series dictates whether the merge appends series to the end of *this or overwrites an existing Series in *this with the same name.
  • The size of series must match the height of *this, or *this must be empty. Otherwise, a std::exception is thrown.
  • The returned Series will always have empty attrs. It is up to the caller to decide how to propagate metadata.

The documentation for this class was generated from the following file: