# Path: datarobot_batch_scoring/exceptions.py
# class UnexpectedKeptColumnCount(Exception):
#     pass
# 
# class NoPredictionThresholdInResult(Exception):
#     pass


import operator
import json
from itertools import chain
from six.moves import zip
from datarobot_batch_scoring.exceptions import UnexpectedKeptColumnCount, \
    NoPredictionThresholdInResult
def keep_original_fields(batch, keep_cols, fast_mode, input_delimiter):
    """ Generate fields from original data

    Parameters
    ----------
    batch
        batch of original data
    keep_cols: list[str]
        columns we should keep
    fast_mode: bool
        faster CSV processor. if True then row in the batch is raw string
    input_delimiter: str, optional
        csv delimiter. should be passed if fast_mode is True

    Returns
    -------
    header: list[str]
    row_generator: iterator
    """

    feature_indices = {col: i for i, col in
                       enumerate(batch.fieldnames)}
    indices = [feature_indices[col] for col in keep_cols]

    def rows_generator():
        for original_row in batch.data:
            if fast_mode:
                # row is a full line, we need to cut it into fields
                original_row = original_row.rstrip().split(input_delimiter)
                if len(original_row) != len(batch.fieldnames):

# Path: datarobot_batch_scoring/exceptions.py
# class UnexpectedKeptColumnCount(Exception):
#     pass
# 
# class NoPredictionThresholdInResult(Exception):
#     pass


# Path: datarobot_batch_scoring/api_response_handlers/pred_api_v10.py
import operator
import json
from itertools import chain
from six.moves import zip
from datarobot_batch_scoring.exceptions import UnexpectedKeptColumnCount, \
    NoPredictionThresholdInResult

def keep_original_fields(batch, keep_cols, fast_mode, input_delimiter):
    """ Generate fields from original data

    Parameters
    ----------
    batch
        batch of original data
    keep_cols: list[str]
        columns we should keep
    fast_mode: bool
        faster CSV processor. if True then row in the batch is raw string
    input_delimiter: str, optional
        csv delimiter. should be passed if fast_mode is True

    Returns
    -------
    header: list[str]
    row_generator: iterator
    """

    feature_indices = {col: i for i, col in
                       enumerate(batch.fieldnames)}
    indices = [feature_indices[col] for col in keep_cols]

    def rows_generator():
        for original_row in batch.data:
            if fast_mode:
                # row is a full line, we need to cut it into fields
                original_row = original_row.rstrip().split(input_delimiter)
                if len(original_row) != len(batch.fieldnames):

                    raise UnexpectedKeptColumnCount()