Path: blob/main/crates/polars-core/src/frame/upstream_traits.rs
8479 views
use std::ops::{Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive};12use arrow::record_batch::RecordBatchT;34use crate::prelude::*;56impl TryExtend<RecordBatchT<Box<dyn Array>>> for DataFrame {7fn try_extend<I: IntoIterator<Item = RecordBatchT<Box<dyn Array>>>>(8&mut self,9iter: I,10) -> PolarsResult<()> {11for record_batch in iter {12self.append_record_batch(record_batch)?;13}1415Ok(())16}17}1819impl TryExtend<PolarsResult<RecordBatchT<Box<dyn Array>>>> for DataFrame {20fn try_extend<I: IntoIterator<Item = PolarsResult<RecordBatchT<Box<dyn Array>>>>>(21&mut self,22iter: I,23) -> PolarsResult<()> {24for record_batch in iter {25self.append_record_batch(record_batch?)?;26}2728Ok(())29}30}3132impl Index<usize> for DataFrame {33type Output = Column;3435fn index(&self, index: usize) -> &Self::Output {36&self.columns()[index]37}38}3940macro_rules! impl_ranges {41($range_type:ty) => {42impl Index<$range_type> for DataFrame {43type Output = [Column];4445fn index(&self, index: $range_type) -> &Self::Output {46&self.columns()[index]47}48}49};50}5152impl_ranges!(Range<usize>);53impl_ranges!(RangeInclusive<usize>);54impl_ranges!(RangeFrom<usize>);55impl_ranges!(RangeTo<usize>);56impl_ranges!(RangeToInclusive<usize>);57impl_ranges!(RangeFull);5859// we don't implement Borrow<str> or AsRef<str> as upstream crates may add impl of trait for usize.60impl Index<&str> for DataFrame {61type Output = Column;6263fn index(&self, index: &str) -> &Self::Output {64self.column(index).unwrap()65}66}676869