<commit_before>#!/usr/bin/env python

import csv
import logging
import os
import simplejson as json
import sys

import memcacheConstants
import pump

def number_try_parse(str):
    for func in (int, float):
        try:
            return func(str)
        except ValueError:
            pass

    return str

class CSVSource(pump.Source):
    """Reads csv file, where first line is field names and one field
       should be 'id'."""

    def __init__(self, opts, spec, source_bucket, source_node,
                 source_map, sink_map, ctl, cur):
        super(CSVSource, self).__init__(opts, spec, source_bucket, source_node,
                                        source_map, sink_map, ctl, cur)
        self.done = False
        self.r = None # An iterator of csv.reader()

    @staticmethod
    def can_handle(opts, spec):<commit_msg>MB-7100: CSV import parses 00000 as a string, not as int 0<commit_after>#!/usr/bin/env python

import csv
import logging
import os
import simplejson as json
import sys

import memcacheConstants
import pump

def number_try_parse(s):
    for func in (int, float):
        try:
            v = func(s)
            if s == str(v):
                return v
        except ValueError:
            pass
    return s

class CSVSource(pump.Source):
    """Reads csv file, where first line is field names and one field
       should be 'id'."""

    def __init__(self, opts, spec, source_bucket, source_node,
                 source_map, sink_map, ctl, cur):
        super(CSVSource, self).__init__(opts, spec, source_bucket, source_node,
                                        source_map, sink_map, ctl, cur)
        self.done = False
        self.r = None # An iterator of csv.reader()

    @staticmethod
    def can_handle(opts, spec):
{'fraction_non_alphanumeric': 0.08418079096045197, 'fraction_numerical': 0.005649717514124294, 'mean_word_length': 2.225865209471767, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7502708', 'n_tokens_mistral': 529, 'n_tokens_neox': 506, 'n_words': 177}