Add dataframe column assertion

This commit is contained in:
coolneng 2020-06-12 19:21:50 +02:00
parent 6849078d88
commit a20dab0053
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
4 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,7 @@
from json import dump from json import dump
from requests import get from requests import get
from constants import FILES, URL from constants import FILES, URL
@ -22,6 +24,7 @@ def save_json(data, dataset):
def request_dataset(dataset): def request_dataset(dataset):
""" """
Fetches the requested dataset from opendata's API Fetches the requested dataset from opendata's API
Raises an exception if there's an HTTP error
""" """
url = format_url(dataset) url = format_url(dataset)
response = get(url) response = get(url)

View File

@ -1,6 +1,8 @@
from json import load from json import load
from pandas import json_normalize, DataFrame
from constants import FILES, COLUMNS from pandas import DataFrame, json_normalize
from constants import COLUMNS, FILES
def open_json(dataset) -> dict: def open_json(dataset) -> dict:

View File

@ -4,7 +4,6 @@ DATASETS = [
"deconfinement-parking-relais-doublement-des-places", "deconfinement-parking-relais-doublement-des-places",
] ]
URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset={}&q=&rows=-1" URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset={}&q=&rows=-1"
TEST_URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset=deconfinement-pistes-cyclables-temporaires&rows=-1"
FILES = { FILES = {
"deconfinement-pistes-cyclables-temporaires": "data/cycling-paths.json", "deconfinement-pistes-cyclables-temporaires": "data/cycling-paths.json",
"deconfinement-parking-relais-doublement-des-places": "data/relay-parking.json", "deconfinement-parking-relais-doublement-des-places": "data/relay-parking.json",

View File

@ -1,9 +1,11 @@
from constants import FILES, DATASETS, URL from os import remove
from app.preprocessing import create_dataframe
from app.request_datasets import request_dataset
from pandas import DataFrame from pandas import DataFrame
from requests import get from requests import get
from os import remove
from app.preprocessing import create_dataframe
from app.data_request import request_dataset
from constants import COLUMNS, DATASETS, FILES, URL
def test_dataset_request(): def test_dataset_request():
@ -24,3 +26,4 @@ def test_dataframe_creation():
df = create_dataframe(dataset) df = create_dataframe(dataset)
remove(FILES[dataset]) remove(FILES[dataset])
assert isinstance(df, DataFrame) assert isinstance(df, DataFrame)
assert all(df.columns == COLUMNS[dataset])