Method: Polars::Functions#corr
- Defined in:
- lib/polars/functions/lazy.rb
#corr(a, b, method: "pearson", ddof: nil, propagate_nans: false, eager: false) ⇒ Expr
Compute the Pearson's or Spearman rank correlation correlation between two columns.
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 |
# File 'lib/polars/functions/lazy.rb', line 774 def corr( a, b, method: "pearson", ddof: nil, propagate_nans: false, eager: false ) if !ddof.nil? Utils.issue_deprecation_warning( "The `ddof` parameter has no effect. Do not use it." ) end if eager if !(a.is_a?(Series) || b.is_a?(Series)) msg = "expected at least one Series in 'corr' inputs if 'eager: true'" raise ArgumentError, msg end frame = Polars::DataFrame.new([a, b].filter_map { |e| e if e.is_a?(Series) }) exprs = [a, b].map { |e| e.is_a?(Series) ? e.name : e } frame.select( corr(*exprs, eager: false, method: method, propagate_nans: propagate_nans) ).to_series else a = Utils.parse_into_expression(a) b = Utils.parse_into_expression(b) if method == "pearson" Utils.wrap_expr(Plr.pearson_corr(a, b)) elsif method == "spearman" Utils.wrap_expr(Plr.spearman_rank_corr(a, b, propagate_nans)) else msg = "method must be one of {{'pearson', 'spearman'}}, got #{method}" raise ArgumentError, msg end end end |