<commit_before># convert date columns to numerics
require "csv"

class Masticate::Datify < Masticate::Base
  def configure(opts)
    standard_options(opts)
    @field = opts[:field] or raise "missing field to datify"
    @format = opts[:format] or raise "strptime format required for parsing timestamps"
  end

  def datify(opts)
    execute(opts)
  end

  def crunch(row)
    if !@index
      if @field.is_a?(Fixnum) || @field =~ /^\d+/
        @index = @field.to_i
      else
        @index = row.index(@field) or raise "Unable to find column '#{@field}'"
      end
    elsif row
      ts = DateTime.strptime(row[@index], @format).to_time
      row[@index] = ts.to_i rescue nil
    end
    row
  end
end
<commit_msg>datetime parsing should not crash on format errors, just output nils<commit_after># convert date columns to numerics

class Masticate::Datify < Masticate::Base
  def configure(opts)
    standard_options(opts)
    @field = opts[:field] or raise "missing field to datify"
    @format = opts[:format] or raise "strptime format required for parsing timestamps"
  end

  def datify(opts)
    execute(opts)
  end

  def crunch(row)
    if !@index
      if @field.is_a?(Fixnum) || @field =~ /^\d+/
        @index = @field.to_i
      else
        @index = row.index(@field) or raise "Unable to find column '#{@field}'"
      end
    elsif row
      row[@index] = DateTime.strptime(row[@index], @format).to_time.to_i rescue nil
    end
    row
  end
end

{'fraction_non_alphanumeric': 0.11483253588516747, 'fraction_numerical': 0.0, 'mean_word_length': 3.021978021978022, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4002673', 'n_tokens_mistral': 490, 'n_tokens_neox': 480, 'n_words': 148}