<commit_before>from __future__ import absolute_import, division, print_function

import os
import re
import subprocess
import uuid
import mmap

from contextlib import closing
from functools import partial
from distutils.spawn import find_executable

import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.elements import Executable, ClauseElement

from toolz import merge
from multipledispatch import MDNotImplementedError

from ..append import append
from ..convert import convert
from .csv import CSV, infer_header
from ..temp import Temp
from .aws import S3
from .sql import fullname


class CopyFromCSV(Executable, ClauseElement):
    def __init__(self, element, csv, delimiter=',', header=None, na_value='',
                 lineterminator='\n', quotechar='"', escapechar='\\',
                 encoding='utf8', skiprows=0, **kwargs):
        if not isinstance(element, sa.Table):
            raise TypeError('element must be a sqlalchemy.Table instance')
        self.element = element
        self.csv = csv
        self.delimiter = delimiter
        self.header = (header if header is not None else
                       (csv.has_header
                        if csv.has_header is not None else infer_header(csv)))<commit_msg>Fix a bug where infer_header(csv) was not being hit<commit_after>from __future__ import absolute_import, division, print_function

import os
import re
import subprocess
import uuid
import mmap

from contextlib import closing
from functools import partial
from distutils.spawn import find_executable

import sqlalchemy as sa
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.elements import Executable, ClauseElement

from toolz import merge
from multipledispatch import MDNotImplementedError

from ..append import append
from ..convert import convert
from .csv import CSV, infer_header
from ..temp import Temp
from .aws import S3
from .sql import fullname


class CopyFromCSV(Executable, ClauseElement):
    def __init__(self, element, csv, delimiter=',', header=None, na_value='',
                 lineterminator='\n', quotechar='"', escapechar='\\',
                 encoding='utf8', skiprows=0, **kwargs):
        if not isinstance(element, sa.Table):
            raise TypeError('element must be a sqlalchemy.Table instance')
        self.element = element
        self.csv = csv
        self.delimiter = delimiter
        self.header = (header if header is not None else
                       (csv.has_header
                        if csv.has_header is not None else infer_header(csv.path)))
{'fraction_non_alphanumeric': 0.07239643825009678, 'fraction_numerical': 0.0023228803716608595, 'mean_word_length': 3.3066666666666666, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '320576', 'n_tokens_mistral': 702, 'n_tokens_neox': 675, 'n_words': 253}