pandrs 0.3.0

A high-performance DataFrame library for Rust, providing pandas-like API with advanced features including SIMD optimization, parallel processing, and distributed computing capabilities
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
//! Core DataFrame operation traits for PandRS
//!
//! This module provides the foundational trait system for all DataFrame-like operations
//! in PandRS, enabling better extensibility, code reuse, and generic programming.

use crate::core::data_value::DataValue;
use crate::core::error::{Error, Result};
use std::collections::HashMap;

/// Axis specification for operations
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Axis {
    Row = 0,
    Column = 1,
}

/// Join types for merge operations
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum JoinType {
    Inner,
    Left,
    Right,
    Outer,
    Cross,
}

/// Methods for handling null values in dropna
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DropNaHow {
    Any, // Drop if any null value
    All, // Drop only if all values are null
}

/// Fill methods for handling null values
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FillMethod {
    Forward,     // Forward fill
    Backward,    // Backward fill
    Zero,        // Fill with zero
    Mean,        // Fill with mean
    Interpolate, // Interpolate values
}

/// DataFrame information structure
#[derive(Debug, Clone)]
pub struct DataFrameInfo {
    pub shape: (usize, usize),
    pub memory_usage: usize,
    pub null_counts: HashMap<String, usize>,
    pub dtypes: HashMap<String, String>,
}

/// Aggregation function specification
#[derive(Debug, Clone)]
pub enum AggFunc {
    Sum,
    Mean,
    Median,
    Min,
    Max,
    Count,
    Std,
    Var,
    Custom(String), // Custom function name
}

/// Base trait for all DataFrame-like structures in PandRS
pub trait DataFrameOps {
    type Output: DataFrameOps;
    type Error: std::error::Error + Send + Sync + 'static;

    // Core structural operations

    /// Select specific columns by name
    fn select(&self, columns: &[&str]) -> Result<Self::Output>;

    /// Drop specific columns by name
    fn drop(&self, columns: &[&str]) -> Result<Self::Output>;

    /// Rename columns using a mapping
    fn rename(&self, mapping: &HashMap<String, String>) -> Result<Self::Output>;

    // Filtering and selection

    /// Filter rows based on a predicate function
    fn filter<F>(&self, predicate: F) -> Result<Self::Output>
    where
        F: Fn(&dyn DataValue) -> bool + Send + Sync;

    /// Get the first n rows
    fn head(&self, n: usize) -> Result<Self::Output>;

    /// Get the last n rows
    fn tail(&self, n: usize) -> Result<Self::Output>;

    /// Sample n random rows
    fn sample(&self, n: usize, random_state: Option<u64>) -> Result<Self::Output>;

    // Sorting and ordering

    /// Sort by column values
    fn sort_values(&self, by: &[&str], ascending: &[bool]) -> Result<Self::Output>;

    /// Sort by index
    fn sort_index(&self) -> Result<Self::Output>;

    // Shape and metadata

    /// Get the shape (rows, columns) of the DataFrame
    fn shape(&self) -> (usize, usize);

    /// Get the column names
    fn columns(&self) -> Vec<String>;

    /// Get the data types of columns
    fn dtypes(&self) -> HashMap<String, String>;

    /// Get comprehensive DataFrame information
    fn info(&self) -> DataFrameInfo;

    // Missing data handling

    /// Drop rows or columns containing null values
    fn dropna(&self, axis: Option<Axis>, how: DropNaHow) -> Result<Self::Output>;

    /// Fill null values
    fn fillna(&self, value: &dyn DataValue, method: Option<FillMethod>) -> Result<Self::Output>;

    /// Check for null values
    fn isna(&self) -> Result<Self::Output>;

    // Transformation operations

    /// Apply a function to each element
    fn map<F>(&self, func: F) -> Result<Self::Output>
    where
        F: Fn(&dyn DataValue) -> Box<dyn DataValue> + Send + Sync;

    /// Apply a function along an axis
    fn apply<F>(&self, func: F, axis: Axis) -> Result<Self::Output>
    where
        F: Fn(&Self::Output) -> Box<dyn DataValue> + Send + Sync;
}

/// Advanced DataFrame operations for complex data manipulation
pub trait DataFrameAdvancedOps: DataFrameOps {
    type GroupBy: GroupByOps<Self>
    where
        Self: Sized;

    // Merging and joining

    /// Merge with another DataFrame
    fn merge(&self, other: &Self, on: &[&str], how: JoinType) -> Result<Self::Output>;

    /// Concatenate with other DataFrames
    fn concat(&self, others: &[&Self], axis: Axis) -> Result<Self::Output>;

    // Reshaping operations

    /// Pivot the DataFrame
    fn pivot(&self, index: &[&str], columns: &[&str], values: &[&str]) -> Result<Self::Output>;

    /// Melt the DataFrame from wide to long format
    fn melt(&self, id_vars: &[&str], value_vars: &[&str]) -> Result<Self::Output>;

    /// Stack columns into a series
    fn stack(&self, level: Option<usize>) -> Result<Self::Output>;

    /// Unstack index into columns
    fn unstack(&self, level: Option<usize>) -> Result<Self::Output>;

    // Grouping operations

    /// Group by columns
    fn group_by(&self, by: &[&str]) -> Result<Self::GroupBy>
    where
        Self: Sized;

    // Window operations

    /// Create rolling window
    fn rolling(&self, window: usize) -> Result<RollingWindow<Self>>
    where
        Self: Sized;

    /// Create expanding window
    fn expanding(&self) -> Result<ExpandingWindow<Self>>
    where
        Self: Sized;

    // Time series operations

    /// Resample time series data
    fn resample(&self, freq: &str) -> Result<Resampler<Self>>
    where
        Self: Sized;

    /// Shift values by periods
    fn shift(&self, periods: i64) -> Result<Self::Output>;

    // Advanced indexing

    /// Set index from columns
    fn set_index(&self, keys: &[&str]) -> Result<Self::Output>;

    /// Reset index to default integer index
    fn reset_index(&self, drop: bool) -> Result<Self::Output>;

    /// Reindex using a new index
    fn reindex<I: IndexTrait>(&self, index: &I) -> Result<Self::Output>;
}

/// GroupBy operations trait
pub trait GroupByOps<T: DataFrameOps> {
    type GroupByResult: DataFrameOps;
    type Error: std::error::Error + Send + Sync + 'static;

    // Basic aggregations

    /// Sum of groups
    fn sum(&self) -> Result<Self::GroupByResult>;

    /// Mean of groups
    fn mean(&self) -> Result<Self::GroupByResult>;

    /// Median of groups
    fn median(&self) -> Result<Self::GroupByResult>;

    /// Standard deviation of groups
    fn std(&self) -> Result<Self::GroupByResult>;

    /// Variance of groups
    fn var(&self) -> Result<Self::GroupByResult>;

    /// Minimum of groups
    fn min(&self) -> Result<Self::GroupByResult>;

    /// Maximum of groups
    fn max(&self) -> Result<Self::GroupByResult>;

    /// Count of non-null values in groups
    fn count(&self) -> Result<Self::GroupByResult>;

    /// Number of unique values in groups
    fn nunique(&self) -> Result<Self::GroupByResult>;

    // Advanced aggregations

    /// Apply multiple aggregation functions
    fn agg(&self, funcs: &[AggFunc]) -> Result<Self::GroupByResult>;

    /// Transform groups with a function
    fn transform<F>(&self, func: F) -> Result<T>
    where
        F: Fn(&T) -> T + Send + Sync;

    /// Apply function to each group
    fn apply<F>(&self, func: F) -> Result<Self::GroupByResult>
    where
        F: Fn(&T) -> Box<dyn DataValue> + Send + Sync;

    // Filtering

    /// Filter groups based on a condition
    fn filter<F>(&self, func: F) -> Result<T>
    where
        F: Fn(&T) -> bool + Send + Sync;

    // Group information

    /// Get group keys
    fn groups(&self) -> GroupIterator<T>
    where
        T: Clone;

    /// Get specific group by key
    fn get_group(&self, key: &GroupKey) -> Result<T>;

    // Statistics

    /// Describe groups with summary statistics
    fn describe(&self) -> Result<Self::GroupByResult>;

    /// Calculate quantile for groups
    fn quantile(&self, q: f64) -> Result<Self::GroupByResult>;
}

/// Indexing operations for advanced data selection
pub trait IndexingOps {
    type Output;
    type Error: std::error::Error + Send + Sync + 'static;

    // Position-based indexing (iloc)

    /// Select by integer position
    fn iloc(&self, row_indexer: &RowIndexer, col_indexer: &ColIndexer) -> Result<Self::Output>;

    /// Get scalar value by position
    fn iloc_scalar(&self, row: usize, col: usize) -> Result<Box<dyn DataValue>>;

    // Label-based indexing (loc)

    /// Select by label
    fn loc(&self, row_indexer: &LabelIndexer, col_indexer: &LabelIndexer) -> Result<Self::Output>;

    /// Get scalar value by label
    fn loc_scalar(&self, row_label: &str, col_label: &str) -> Result<Box<dyn DataValue>>;

    // Boolean indexing

    /// Select using boolean mask
    fn mask(&self, mask: &BooleanMask) -> Result<Self::Output>;

    /// Select where condition is true
    fn where_condition<F>(&self, condition: F) -> Result<Self::Output>
    where
        F: Fn(&dyn DataValue) -> bool + Send + Sync;

    // Query-based selection

    /// Query using expression string
    fn query(&self, expression: &str) -> Result<Self::Output>;

    /// Evaluate expression and return series
    fn eval(&self, expression: &str) -> Result<Self::Output>;

    // Fast scalar access

    /// Fast scalar access by label
    fn at(&self, row_label: &str, col_label: &str) -> Result<Box<dyn DataValue>>;

    /// Fast scalar access by position
    fn iat(&self, row: usize, col: usize) -> Result<Box<dyn DataValue>>;
}

// Supporting types and traits

/// Trait for index operations
pub trait IndexTrait: Clone + Send + Sync {
    fn len(&self) -> usize;
    fn get(&self, pos: usize) -> Option<&str>;
    fn position(&self, label: &str) -> Option<usize>;
}

/// Row indexer for iloc operations
#[derive(Debug, Clone)]
pub enum RowIndexer {
    Single(usize),
    Range(std::ops::Range<usize>),
    List(Vec<usize>),
    Slice(usize, Option<usize>, Option<isize>), // start, end, step
}

/// Column indexer for iloc operations
#[derive(Debug, Clone)]
pub enum ColIndexer {
    Single(usize),
    Range(std::ops::Range<usize>),
    List(Vec<usize>),
    All,
}

/// Label indexer for loc operations
#[derive(Debug, Clone)]
pub enum LabelIndexer {
    Single(String),
    List(Vec<String>),
    Slice(String, Option<String>), // start, end
    All,
}

/// Boolean mask for filtering
#[derive(Debug, Clone)]
pub struct BooleanMask {
    pub mask: Vec<bool>,
}

impl BooleanMask {
    pub fn new(mask: Vec<bool>) -> Self {
        Self { mask }
    }

    pub fn len(&self) -> usize {
        self.mask.len()
    }

    pub fn get(&self, index: usize) -> Option<bool> {
        self.mask.get(index).copied()
    }
}

/// Group key for groupby operations
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct GroupKey {
    pub values: Vec<String>,
}

impl GroupKey {
    pub fn new(values: Vec<String>) -> Self {
        Self { values }
    }
}

/// Iterator over groups
pub struct GroupIterator<T>
where
    T: Clone,
{
    groups: Vec<(GroupKey, T)>,
    current: usize,
}

impl<T> GroupIterator<T>
where
    T: Clone,
{
    pub fn new(groups: Vec<(GroupKey, T)>) -> Self {
        Self { groups, current: 0 }
    }
}

impl<T> Iterator for GroupIterator<T>
where
    T: Clone,
{
    type Item = (GroupKey, T);

    fn next(&mut self) -> Option<Self::Item> {
        if self.current < self.groups.len() {
            let result = self.groups.get(self.current)?.clone();
            self.current += 1;
            Some(result)
        } else {
            None
        }
    }
}

/// Rolling window for time-based operations
pub struct RollingWindow<T> {
    dataframe: T,
    window_size: usize,
    min_periods: Option<usize>,
}

impl<T> RollingWindow<T> {
    pub fn new(dataframe: T, window_size: usize) -> Self {
        Self {
            dataframe,
            window_size,
            min_periods: None,
        }
    }

    pub fn min_periods(mut self, min_periods: usize) -> Self {
        self.min_periods = Some(min_periods);
        self
    }
}

impl<T: DataFrameOps> RollingWindow<T> {
    /// Calculate rolling sum
    pub fn sum(&self) -> Result<T::Output> {
        // Apply rolling window operation with sum aggregation
        // This is a placeholder implementation - in practice this would need
        // to work with the actual DataFrame implementation
        Err(Error::NotImplemented(
            "Rolling sum requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate rolling mean
    pub fn mean(&self) -> Result<T::Output> {
        // Apply rolling window operation with mean aggregation
        // This is a placeholder implementation - in practice this would need
        // to work with the actual DataFrame implementation
        Err(Error::NotImplemented(
            "Rolling mean requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate rolling standard deviation
    pub fn std(&self) -> Result<T::Output> {
        // Apply rolling window operation with std aggregation
        // This is a placeholder implementation - in practice this would need
        // to work with the actual DataFrame implementation
        Err(Error::NotImplemented(
            "Rolling std requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate rolling minimum
    pub fn min(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Rolling min requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate rolling maximum
    pub fn max(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Rolling max requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate rolling count
    pub fn count(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Rolling count requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Apply custom rolling function
    pub fn apply<F>(&self, _func: F) -> Result<T::Output>
    where
        F: Fn(&[f64]) -> f64 + Send + Sync,
    {
        Err(Error::NotImplemented(
            "Rolling apply requires DataFrame-specific implementation".to_string(),
        ))
    }
}

/// Expanding window for cumulative operations
pub struct ExpandingWindow<T> {
    dataframe: T,
    min_periods: Option<usize>,
}

impl<T> ExpandingWindow<T> {
    pub fn new(dataframe: T) -> Self {
        Self {
            dataframe,
            min_periods: None,
        }
    }

    pub fn min_periods(mut self, min_periods: usize) -> Self {
        self.min_periods = Some(min_periods);
        self
    }
}

impl<T: DataFrameOps> ExpandingWindow<T> {
    /// Calculate expanding sum
    pub fn sum(&self) -> Result<T::Output> {
        // Apply expanding window operation with sum aggregation
        // This is a placeholder implementation - in practice this would need
        // to work with the actual DataFrame implementation
        Err(Error::NotImplemented(
            "Expanding sum requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate expanding mean
    pub fn mean(&self) -> Result<T::Output> {
        // Apply expanding window operation with mean aggregation
        // This is a placeholder implementation - in practice this would need
        // to work with the actual DataFrame implementation
        Err(Error::NotImplemented(
            "Expanding mean requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate expanding standard deviation
    pub fn std(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Expanding std requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate expanding variance
    pub fn var(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Expanding var requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate expanding minimum
    pub fn min(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Expanding min requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate expanding maximum
    pub fn max(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Expanding max requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Calculate expanding count
    pub fn count(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Expanding count requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Apply custom expanding function
    pub fn apply<F>(&self, _func: F) -> Result<T::Output>
    where
        F: Fn(&[f64]) -> f64 + Send + Sync,
    {
        Err(Error::NotImplemented(
            "Expanding apply requires DataFrame-specific implementation".to_string(),
        ))
    }
}

/// Resampler for time series operations
pub struct Resampler<T> {
    dataframe: T,
    frequency: String,
}

impl<T> Resampler<T> {
    pub fn new(dataframe: T, frequency: String) -> Self {
        Self {
            dataframe,
            frequency,
        }
    }
}

impl<T: DataFrameOps> Resampler<T> {
    /// Resample and sum
    pub fn sum(&self) -> Result<T::Output> {
        // Parse frequency and apply resampling with sum aggregation
        // This is a placeholder implementation - in practice this would need
        // to work with the actual DataFrame implementation and parse the frequency string
        Err(Error::NotImplemented(
            "Resample sum requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and take mean
    pub fn mean(&self) -> Result<T::Output> {
        // Parse frequency and apply resampling with mean aggregation
        Err(Error::NotImplemented(
            "Resample mean requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and take first value
    pub fn first(&self) -> Result<T::Output> {
        // Parse frequency and apply resampling taking first value
        Err(Error::NotImplemented(
            "Resample first requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and take last value
    pub fn last(&self) -> Result<T::Output> {
        // Parse frequency and apply resampling taking last value
        Err(Error::NotImplemented(
            "Resample last requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and calculate standard deviation
    pub fn std(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Resample std requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and calculate variance
    pub fn var(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Resample var requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and find minimum
    pub fn min(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Resample min requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and find maximum
    pub fn max(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Resample max requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Resample and count values
    pub fn count(&self) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Resample count requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Apply custom aggregation function to resampled data
    pub fn agg(&self, _funcs: &[AggFunc]) -> Result<T::Output> {
        Err(Error::NotImplemented(
            "Resample agg requires DataFrame-specific implementation".to_string(),
        ))
    }

    /// Get the frequency string
    pub fn frequency(&self) -> &str {
        &self.frequency
    }
}

/// Trait for statistical operations on DataFrames
pub trait StatisticalOps: DataFrameOps {
    /// Calculate descriptive statistics
    fn describe(&self) -> Result<Self::Output>;

    /// Calculate correlation matrix
    fn corr(&self, method: CorrelationMethod) -> Result<Self::Output>;

    /// Calculate covariance matrix
    fn cov(&self) -> Result<Self::Output>;

    /// Calculate quantiles
    fn quantile(&self, q: &[f64]) -> Result<Self::Output>;

    /// Calculate value counts
    fn value_counts(&self, column: &str) -> Result<Self::Output>;

    /// Check for duplicate rows
    fn duplicated(&self, subset: Option<&[&str]>) -> Result<BooleanMask>;

    /// Remove duplicate rows
    fn drop_duplicates(&self, subset: Option<&[&str]>) -> Result<Self::Output>;
}

/// Correlation calculation methods
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CorrelationMethod {
    Pearson,
    Spearman,
    Kendall,
}

/// Trait for I/O operations on DataFrames
pub trait DataFrameIO: DataFrameOps {
    /// Read from CSV file
    fn read_csv(path: &str, options: CsvReadOptions) -> Result<Self::Output>;

    /// Write to CSV file
    fn to_csv(&self, path: &str, options: CsvWriteOptions) -> Result<()>;

    /// Read from JSON file
    fn read_json(path: &str, options: JsonReadOptions) -> Result<Self::Output>;

    /// Write to JSON file
    fn to_json(&self, path: &str, options: JsonWriteOptions) -> Result<()>;

    /// Read from Parquet file
    fn read_parquet(path: &str, options: ParquetReadOptions) -> Result<Self::Output>;

    /// Write to Parquet file
    fn to_parquet(&self, path: &str, options: ParquetWriteOptions) -> Result<()>;
}

/// CSV reading options
#[derive(Debug, Clone, Default)]
pub struct CsvReadOptions {
    pub delimiter: Option<char>,
    pub header: Option<bool>,
    pub skip_rows: Option<usize>,
    pub nrows: Option<usize>,
    pub encoding: Option<String>,
}

/// CSV writing options
#[derive(Debug, Clone, Default)]
pub struct CsvWriteOptions {
    pub delimiter: Option<char>,
    pub header: Option<bool>,
    pub index: Option<bool>,
    pub encoding: Option<String>,
}

/// JSON reading options
#[derive(Debug, Clone, Default)]
pub struct JsonReadOptions {
    pub orient: Option<String>,
    pub encoding: Option<String>,
}

/// JSON writing options
#[derive(Debug, Clone, Default)]
pub struct JsonWriteOptions {
    pub orient: Option<String>,
    pub encoding: Option<String>,
    pub indent: Option<usize>,
}

/// Parquet reading options
#[derive(Debug, Clone, Default)]
pub struct ParquetReadOptions {
    pub columns: Option<Vec<String>>,
    pub use_threads: Option<bool>,
}

/// Parquet writing options
#[derive(Debug, Clone, Default)]
pub struct ParquetWriteOptions {
    pub compression: Option<String>,
    pub use_dictionary: Option<bool>,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_boolean_mask() {
        let mask = BooleanMask::new(vec![true, false, true, false]);
        assert_eq!(mask.len(), 4);
        assert_eq!(mask.get(0), Some(true));
        assert_eq!(mask.get(1), Some(false));
        assert_eq!(mask.get(4), None);
    }

    #[test]
    fn test_group_key() {
        let key1 = GroupKey::new(vec!["A".to_string(), "1".to_string()]);
        let key2 = GroupKey::new(vec!["A".to_string(), "1".to_string()]);
        let key3 = GroupKey::new(vec!["B".to_string(), "2".to_string()]);

        assert_eq!(key1, key2);
        assert_ne!(key1, key3);
    }

    #[test]
    fn test_indexers() {
        let row_indexer = RowIndexer::Range(0..5);
        let col_indexer = ColIndexer::List(vec![0, 2, 4]);

        match row_indexer {
            RowIndexer::Range(range) => assert_eq!(range, 0..5),
            _ => panic!("Wrong indexer type"),
        }

        match col_indexer {
            ColIndexer::List(list) => assert_eq!(list, vec![0, 2, 4]),
            _ => panic!("Wrong indexer type"),
        }
    }
}