<commit_before>import numpy as np
import json
import os
from pseudodata import PseudoData


class Sweep(object):
    """
    Parameters
    ----------
    path : str
        Full path to a directory containing at least a data.dat and a meta.json
        file.

    Attributes
    ----------
    data : numpy structured array
        Contains the data from data.dat with names given by the columns key in
        meta.json.
    meta : dictionary
        Contains meta.json as a dictionary.

    Notes
    -----
    This class currently supports loading data with a dimension of 1 or 2.
    """
    def __init__(self, path):
        self.path = path
        self.load()
        self.dimension = self.get_dimension(self.meta)
        if self.dimension == 2:
            self.get2d()
        elif self.dimension > 2:
            err_str = 'Data dimensions higher than 2 are not supported.'
            raise RuntimeError(err_str)

    def load(self):
        (self.data, self.meta) = self.load_dir(self.path)

    def get2d(self):
        """
        data_1D is a numpy structured array of dimension 1. If the sweep
        contains 2D data we must reshape data_1D according to the columns of
        the channels that are swept.
        """
        (data_1D, meta) = (self.data, self.meta)
        c1, c2 = data_1D.dtype.names[:2]
        reshaped_data = self.reshape2d(data_1D[c1], data_1D[c2], data_1D)
        (self.data, self.meta) = reshaped_data, meta

    def set_pdata(self, name_func_dict=None):
        if name_func_dict is None:
            return
        self.pdata = PseudoData(name_func_dict, self)
        self.name_func_dict = name_func_dict

    def get_label(self, col_name):
        try:
            return self.name_func_dict[col_name]['label']
        except KeyError:
            return col_name<commit_msg>Add method get_data to sweep.py<commit_after>import numpy as np
import json
import os
from pseudodata import PseudoData


class Sweep(object):
    """
    Parameters
    ----------
    path : str
        Full path to a directory containing at least a data.dat and a meta.json
        file.

    Attributes
    ----------
    data : numpy structured array
        Contains the data from data.dat with names given by the columns key in
        meta.json.
    meta : dictionary
        Contains meta.json as a dictionary.

    Notes
    -----
    This class currently supports loading data with a dimension of 1 or 2.
    """
    def __init__(self, path):
        self.path = path
        self.load()
        self.dimension = self.get_dimension(self.meta)
        if self.dimension == 2:
            self.get2d()
        elif self.dimension > 2:
            err_str = 'Data dimensions higher than 2 are not supported.'
            raise RuntimeError(err_str)

    def load(self):
        (self.data, self.meta) = self.load_dir(self.path)

    def get2d(self):
        """
        data_1D is a numpy structured array of dimension 1. If the sweep
        contains 2D data we must reshape data_1D according to the columns of
        the channels that are swept.
        """
        (data_1D, meta) = (self.data, self.meta)
        c1, c2 = data_1D.dtype.names[:2]
        reshaped_data = self.reshape2d(data_1D[c1], data_1D[c2], data_1D)
        (self.data, self.meta) = reshaped_data, meta

    def set_pdata(self, name_func_dict=None):
        if name_func_dict is None:
            return
        self.pdata = PseudoData(name_func_dict, self)
        self.name_func_dict = name_func_dict

    def get_label(self, col_name):
        try:
            return self.name_func_dict[col_name]['label']
        except KeyError:
            return col_name

    def get_data(self, col_name):
        try:
            return self.data[col_name]
        except ValueError:
            pass
        try:
            return self.pdata[col_name]
        except KeyError:
            raise ValueError('{} not found in data or pdata'.format(col_name))
{'fraction_non_alphanumeric': 0.08842849924204144, 'fraction_numerical': 0.011116725618999495, 'mean_word_length': 2.012937595129376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '430603', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1154, 'n_words': 367}