Skip to content

Commit

Permalink
Update extract_segments_of_year
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentAntoine committed Dec 10, 2024
1 parent e0b2a23 commit bd9f3f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SELECT
SELECT
year,
segment,
segment_name,
gears,
Expand All @@ -12,4 +13,5 @@ SELECT
vessel_types,
impact_risk_factor
FROM public.fleet_segments
WHERE year = :year
WHERE year = :year
ORDER BY segment
40 changes: 12 additions & 28 deletions datascience/tests/test_pipeline/test_shared_tasks/test_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@


@pytest.fixture
def expected_all_segments() -> pd.DataFrame:
current_year = datetime.utcnow().year
def current_year() -> int:
return datetime.utcnow().year


@pytest.fixture
def expected_all_segments(current_year) -> pd.DataFrame:
expected_segments = pd.DataFrame(
{
"year": [2022, 2022, current_year, current_year],
Expand Down Expand Up @@ -59,38 +63,18 @@ def expected_all_segments() -> pd.DataFrame:


@pytest.fixture
def expected_segments_of_year() -> pd.DataFrame:
return pd.DataFrame(
{
"segment": ["SWW01/02/03", "SWW04"],
"segment_name": ["Bottom trawls", "Midwater trawls"],
"gears": [
["OTB", "OTT", "PTB", "OT", "PT", "TBN", "TBS", "TX", "TB"],
["OTM", "PTM"],
],
"fao_areas": [["27.8.c", "27.8", "27.9"], ["27.8.c", "27.8"]],
"min_mesh": [80.0, None],
"max_mesh": [120.0, None],
"target_species": [["HKE", "SOL", "ANF", "MNZ", "NEP", "LEZ"], ["HKE"]],
"min_share_of_target_species": [0.0, 0.0],
"main_scip_species_type": ["DEMERSAL", "PELAGIC"],
"priority": [0.0, 1.0],
"vessel_types": [
None,
["Navire qui pêche", "Chalutier", "Ligneur", "Navire qui navigue"],
],
"impact_risk_factor": [3.0, 2.1],
}
)
def expected_segments_of_current_year(expected_all_segments) -> pd.DataFrame:
return expected_all_segments.loc[2:4].reset_index(drop=True)


def test_extract_segments_of_year(reset_test_data, expected_segments_of_year):
current_year = datetime.utcnow().year
def test_extract_segments_of_year(
reset_test_data, expected_segments_of_current_year, current_year
):
segments = extract_segments_of_year.run(current_year)

pd.testing.assert_frame_equal(
segments.sort_values("segment").reset_index(drop=True),
expected_segments_of_year,
expected_segments_of_current_year,
)


Expand Down

0 comments on commit bd9f3f3

Please sign in to comment.