Пример #1
0
def test_load_csv():
    csv = loader.load_csv('boat.csv')

    assert csv is None

    csv = loader.load_csv('data/boat.csv')

    assert csv.shape == (100, 4)
Пример #2
0
    def _load(self, file_path):
        """Loads and parses a dataframe from a file.

        Args:
            file_path (str): File to be loaded.

        Returns:
            Arrays holding the features and labels.

        """

        # Getting file extension
        extension = file_path.split('.')[-1]

        if extension == 'csv':
            data = loader.load_csv(file_path)

        elif extension == 'txt':
            data = loader.load_txt(file_path)

        elif extension == 'json':
            data = loader.load_json(file_path)

        else:
            raise e.ArgumentError(
                'File extension not recognized. It should be `.csv`, `.json` or `.txt`'
            )

        X, Y = p.parse_loader(data)

        return X, Y
Пример #3
0
    def _read_distances(self, file_name):
        """Reads the distance between nodes from a pre-defined file.

        Args:
            file_name (str): File to be loaded.

        """

        logger.debug('Running private method: read_distances().')

        # Getting file extension
        extension = file_name.split('.')[-1]

        if extension == 'csv':
            distances = loader.load_csv(file_name)

        elif extension == 'txt':
            distances = loader.load_txt(file_name)

        else:
            # Raises an ArgumentError exception
            raise e.ArgumentError('File extension not recognized. It should be either `.csv` or .txt`')

        # Check if distances have been properly loaded
        if distances is None:
            raise e.ValueError('Pre-computed distances could not been properly loaded')

        # Apply the distances matrix to the property
        self.pre_distances = distances
Пример #4
0
def test_parse_loader():
    X, Y = parser.parse_loader([])

    assert X is None
    assert Y is None

    try:
        data = np.ones((4, 4))
        X, Y = parser.parse_loader(data)
    except:
        try:
            data = np.ones((4, 4))
            data[3, 1] = 3
            X, Y = parser.parse_loader(data)
        except:
            csv = loader.load_csv('data/boat.csv')

            X, Y = parser.parse_loader(csv)

            assert X.shape == (100, 2)
            assert Y.shape == (100, )
Пример #5
0
    def _load(self, file_path):
        """Loads and parses a dataframe from a file.

        Args:
            file_path (str): File to be loaded.

        Returns:
            Arrays holding the features and labels.

        """

        # Getting file extension
        extension = file_path.split('.')[-1]

        # Check if extension is .csv
        if extension == 'csv':
            # If yes, call the method that actually loads csv
            data = loader.load_csv(file_path)

        # Check if extension is .txt
        elif extension == 'txt':
            # If yes, call the method that actually loads txt
            data = loader.load_txt(file_path)

        # Check if extension is .json
        elif extension == 'json':
            # If yes, call the method that actually loads json
            data = loader.load_json(file_path)

        # If extension is not recognized
        else:
            # Raises an ArgumentError exception
            raise e.ArgumentError(
                'File extension not recognized. It should be `.csv`, `.json` or `.txt`'
            )

        # Parsing array
        X, Y = p.parse_loader(data)

        return X, Y
Пример #6
0
    def _read_distances(self, file_path):
        """Reads the distance between nodes from a pre-defined file.

        Args:
            file_path (str): File to be loaded.

        Returns:
            A matrix with pre-computed distances.

        """

        logger.debug('Running private method: read_distances().')

        # Getting file extension
        extension = file_path.split('.')[-1]

        # Check if extension is .csv
        if extension == 'csv':
            # If yes, call the method that actually loads csv
            distances = loader.load_csv(file_path)

        # Check if extension is .txt
        elif extension == 'txt':
            # If yes, call the method that actually loads txt
            distances = loader.load_txt(file_path)

        # If extension is not recognized
        else:
            # Raises an ArgumentError exception
            raise e.ArgumentError(
                'File extension not recognized. It should be either `.csv` or .txt`'
            )

        # Check if distances have been properly loaded
        if distances is None:
            # If not, raises a ValueError
            raise e.ValueError(
                'Pre-computed distances could not been properly loaded')

        return distances
Пример #7
0
import numpy as np
import pytest

from opfython.math import distance
from opfython.stream import loader, parser
from opfython.subgraphs import knn

csv = loader.load_csv('data/boat.csv')
X, Y = parser.parse_loader(csv)


def test_knn_subgraph_n_clusters():
    subgraph = knn.KNNSubgraph(X, Y)

    assert subgraph.n_clusters == 0


def test_knn_subgraph_n_clusters_setter():
    subgraph = knn.KNNSubgraph(X, Y)

    try:
        subgraph.n_clusters = 0.5
    except:
        subgraph.n_clusters = 1

    assert subgraph.n_clusters == 1

    try:
        subgraph.n_clusters = -1
    except:
        subgraph.n_clusters = 1
Пример #8
0
import opfython.stream.loader as l

# Loading a .csv file
csv = l.load_csv('data/sample.csv')

# Loading a .txt file
txt = l.load_txt('data/sample.txt')

# Loading a .json file
json = l.load_json('data/sample.json')
Пример #9
0
import opfython.stream.loader as l

# Loading a .csv file
csv = l.load_csv('data/boat.csv')

# Loading a .txt file
txt = l.load_txt('data/boat.txt')

# Loading a .json file
json = l.load_json('data/boat.json')