-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_row_order.py
57 lines (46 loc) · 1.91 KB
/
test_row_order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pandas as pd
import pytest
from load import dfs
def test_source_sorted_by_id() -> None:
"""Sources are sorted by ascending id."""
df = dfs['source']
valid = df['id'].index == df['id'].sort_values().index
assert valid.all(), df.loc[~valid, ['id']]
def test_borehole_sorted_by_id() -> None:
"""Boreholes are sorted by ascending id."""
df = dfs['borehole']
valid = df['id'].index == df['id'].sort_values().index
assert valid.all(), df.loc[~valid, ['id']]
@pytest.mark.parametrize(
'path',
dfs['profile']['__path__'].drop_duplicates().to_list()
)
def test_profile_sorted_by_ids(path: str) -> None:
"""Profiles (in each file) are sorted by ascending borehole and profile id."""
mask = dfs['profile']['__path__'].eq(path)
df = dfs['profile'][mask]
index = pd.MultiIndex.from_frame(df[['borehole_id', 'id']])
valid = index == index.sort_values()
assert valid.all(), df[~valid]
@pytest.mark.parametrize(
'path',
dfs['measurement']['__path__'].drop_duplicates().to_list()
)
def test_measurement_sorted_by_ids(path: str) -> None:
"""Measurements (in each file) are sorted by ascending borehole and profile id."""
mask = dfs['measurement']['__path__'].eq(path)
df = dfs['measurement'][mask]
index = pd.MultiIndex.from_frame(df[['borehole_id', 'profile_id']])
valid = index == index.sort_values()
assert valid.all(), df.loc[~valid, ['borehole_id', 'profile_id']].drop_duplicates()
@pytest.mark.parametrize(
'path',
dfs['measurement']['__path__'].drop_duplicates().to_list()
)
def test_measurement_sorted_by_ids_and_depth(path: str) -> None:
"""Measurements (in each file) are sorted by ascending ids and depth."""
mask = dfs['measurement']['__path__'].eq(path)
df = dfs['measurement'][mask]
index = pd.MultiIndex.from_frame(df[['borehole_id', 'profile_id', 'depth']])
valid = index == index.sort_values()
assert valid.all(), df.loc[~valid, ['borehole_id', 'profile_id']].drop_duplicates()