Sha256: 33b2cec0c007148a2d9f0e2023c1095995e1b687ed75a3c527268d2dfba0958f

Contents?: true

Size: 1.09 KB

Versions: 27

Compression:

Stored size: 1.09 KB

Contents

module EasyML
  module Data
    module FilterExtensions
      def is_primary_key_filter?(primary_key)
        return false unless primary_key
        primary_key = [primary_key] unless primary_key.is_a?(Array)
        # Filter expressions in Polars are represented as strings like:
        # [([(col("LOAN_APP_ID")) > (dyn int: 4)]) & ([(col("LOAN_APP_ID")) < (dyn int: 16)])]
        expr_str = to_s
        return false unless expr_str.include?(primary_key.first)

        # Check for common primary key operations
        primary_key_ops = [">", "<", ">=", "<=", "=", "eq", "gt", "lt", "ge", "le"]
        primary_key_ops.any? { |op| expr_str.include?(op) }
      end

      def extract_primary_key_values
        expr_str = to_s
        # Extract numeric values from the expression
        # This will match both integers and floats
        values = expr_str.scan(/(?:dyn int|float): (-?\d+(?:\.\d+)?)/).flatten.map(&:to_f)
        values.uniq
      end
    end
  end
end

# Extend Polars classes with our filter functionality
[Polars::Expr].each do |klass|
  klass.include(EasyML::Data::FilterExtensions)
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
easy_ml-0.2.0.pre.rc27 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc26 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc25 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc24 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc23 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc22 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc21 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc20 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc19 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc18 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc17 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc16 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc15 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc14 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc13 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc12 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc11 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc10 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc9 lib/easy_ml/data/filter_extensions.rb
easy_ml-0.2.0.pre.rc8 lib/easy_ml/data/filter_extensions.rb