Skip to content

Commit ed53649

Browse files
committed
feat(pandas): add problem 620
1 parent dfe87d5 commit ed53649

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Fiddling around with DataFusion, pandas, and PyArrow.
3030

3131
| Problem # | Title | Difficulty | PyArrow | DataFusion | pandas |
3232
|----------:|:------|:-----------|:-------:|:----------:|:------:|
33-
| 620 | [Not Boring Movies](https://leetcode.com/problems/not-boring-movies) | Easy ||| |
33+
| 620 | [Not Boring Movies](https://leetcode.com/problems/not-boring-movies) | Easy ||| |
3434
| 1251 | [Average Selling Price](https://leetcode.com/problems/average-selling-price) | Easy ||||
3535
| 1075 | [Project Employees I](https://leetcode.com/problems/project-employees-i) | Easy ||||
3636
| 1633 | [Percentage of Users Attended a Contest](https://leetcode.com/problems/percentage-of-users-attended-a-contest) | Easy ||||

problems/pandas.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ def problem_197(weather: pd.DataFrame) -> pd.DataFrame:
8585
return weather[mask][["id"]]
8686

8787

88+
def problem_620(cinema: pd.DataFrame) -> pd.DataFrame:
89+
"""Report movies with odd IDs and descriptions not equal to "boring".
90+
91+
Return the result table ordered by rating in descending order.
92+
93+
Parameters
94+
----------
95+
cinema : pd.DataFrame
96+
Table contains information about the name of a movie, genre, and its rating.
97+
98+
Returns
99+
-------
100+
pd.DataFrame
101+
102+
"""
103+
mask = (cinema["id"] % 2 == 1) & (cinema["description"] != "boring")
104+
return cinema[mask].sort_values("rating", ascending=False)
105+
106+
88107
def problem_577(employee: pd.DataFrame, bonus: pd.DataFrame) -> pd.DataFrame:
89108
"""Report the name and bonus amount of each employee with a bonus less than 1000.
90109

tests/test_pandas.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
problem_577,
1313
problem_584,
1414
problem_595,
15+
problem_620,
1516
problem_1068,
1617
problem_1148,
1718
problem_1280,
@@ -357,6 +358,57 @@ def test_problem_595(input_data, expected_data):
357358
), f"Expected table {expected_table}, but got {result}"
358359

359360

361+
@pytest.mark.parametrize(
362+
"input_data, expected_data",
363+
[
364+
pytest.param(
365+
{
366+
"id": [1, 2, 3, 4],
367+
"description": ["interesting", "boring", "exciting", "boring"],
368+
"rating": [3, 1, 1, 1],
369+
},
370+
{
371+
"id": [1, 3],
372+
"description": ["interesting", "exciting"],
373+
"rating": [3, 1],
374+
},
375+
id="happy_path_mixed_ids_and_descriptions",
376+
),
377+
pytest.param(
378+
{"id": [1, 3], "description": ["boring", "boring"], "rating": [1, 1]},
379+
{"id": [], "description": [], "rating": []},
380+
id="edge_case_all_boring",
381+
),
382+
pytest.param(
383+
{
384+
"id": [2, 4],
385+
"description": ["interesting", "exciting"],
386+
"rating": [1, 1],
387+
},
388+
{"id": [], "description": [], "rating": []},
389+
id="edge_case_no_odd_ids",
390+
),
391+
pytest.param(
392+
{"id": [1], "description": ["interesting"], "rating": [1]},
393+
{"id": [1], "description": ["interesting"], "rating": [1]},
394+
id="edge_case_single_row_matching",
395+
),
396+
pytest.param(
397+
{"id": [2], "description": ["boring"], "rating": [1]},
398+
{"id": [], "description": [], "rating": []},
399+
id="edge_case_single_row_not_matching",
400+
),
401+
],
402+
)
403+
def test_problem_620(input_data, expected_data):
404+
table = pd.DataFrame(input_data)
405+
expected_table = pd.DataFrame(expected_data)
406+
result = problem_620(table).reset_index(drop=True)
407+
assert_frame_equal(
408+
result, expected_table, check_dtype=False, check_index_type=False
409+
)
410+
411+
360412
@pytest.mark.parametrize(
361413
"input_data_1, input_data_2, expected_data",
362414
[

0 commit comments

Comments
 (0)