Repository navigation
Mareh A. #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mareh-aboghanem
wants to merge
1
commit into
HackYourAssignment:main
Choose a base branch
from
mareh-aboghanem:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mareh A. #6
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| transaction_id,product_name,category,price,quantity,customer_email,date,revenue,vat | ||
| 1,Laptop Pro,Electronics,999.99,2,[email protected],2024-03-15,1999.98,420.0 | ||
| 2,Wireless Mouse,Electronics,29.99,5,[email protected],2024-03-15,149.95,31.49 | ||
| 3,Usb Cable,Electronics,4.99,10,,2024-03-16,49.9,10.48 | ||
| 4,Office Chair,Furniture,349.5,1,[email protected],2024-03-16,349.5,73.39 | ||
| 5,Standing Desk,Furniture,599.0,1,[email protected],not_a_date,599.0,125.79 | ||
| 8,Monitor Arm,Furniture,79.99,0,[email protected],2024-03-18,0.0,0.0 | ||
| 9,Webcam Hd,Electronics,54.99,1,,2024-03-18,54.99,11.55 | ||
| 10,Desk Lamp,Furniture,34.99,4,[email protected],2024-03-19,139.96,29.39 | ||
| 11,Noise Cancelling Headphones,Electronics,199.99,1,[email protected],2024-03-19,199.99,42.0 | ||
| 12,Cable Management Kit,Furniture,15.99,6,[email protected],2024-03-20,95.94,20.15 | ||
| 13,Ergonomic Mouse Pad,Furniture,24.99,3,[email protected],2024-03-20,74.97,15.74 | ||
| 14,Laptop Stand,Furniture,45.99,2,[email protected],2024-03-21,91.98,19.32 | ||
| 15,Bluetooth Speaker,Unknown,39.99,1,[email protected],2024-03-21,39.99,8.4 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file added
BIN
+7.81 KB
task-1/tests/__pycache__/test_transforms.cpython-311-pytest-9.0.3.pyc
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,5 @@ | ||
| """Tests for the pure transform functions (chapter Task 5). | ||
|
|
||
| Write at least 4 tests: | ||
| - test_remove_invalid_drops_empty_names | ||
| - test_clean_fields_normalizes_names | ||
| - test_calculate_revenue_adds_fields | ||
| - test_no_mutation | ||
| """ | ||
| import pytest | ||
| import copy | ||
|
|
||
| from src.transforms import ( | ||
| calculate_revenue, | ||
|
|
@@ -17,24 +10,43 @@ | |
|
|
||
|
|
||
| def test_remove_invalid_drops_empty_names(): | ||
| # TODO: feed in 3 rows (one valid, one empty product_name, one | ||
| # whitespace-only product_name); assert only the valid one survives. | ||
| raise NotImplementedError | ||
| data = [ | ||
| {"product_name": "Laptop", "price": 999.99}, | ||
| {"product_name": "", "price": 50.0}, | ||
| {"product_name": " ", "price": 25.0}, | ||
| ] | ||
| result = remove_invalid(data) | ||
| assert len(result) == 1 | ||
| assert result[0]["product_name"] == "Laptop" | ||
|
|
||
|
|
||
| def test_clean_fields_normalizes_names(): | ||
| # TODO: feed a row with messy product_name and uppercase email; assert | ||
| # the output has stripped + title-cased name and lowercase email. | ||
| raise NotImplementedError | ||
| data = [ | ||
| {"product_name": " laptop", "customer_email": "[email protected]"} | ||
| ] | ||
| result = clean_fields(data) | ||
|
|
||
| assert len(result) == 1 | ||
| assert result[0]["product_name"] == "Laptop" | ||
| assert result[0]["customer_email"] == "[email protected]" | ||
|
|
||
|
|
||
| def test_calculate_revenue_adds_fields(): | ||
| # TODO: feed a row with price=100, quantity=3; assert output has | ||
| # revenue=300.0 and vat=63.0 (default VAT rate is 0.21). | ||
| raise NotImplementedError | ||
| data = [ | ||
| {"product_name": "Laptop", "price": 100.0, "quantity": 3} | ||
| ] | ||
| result = calculate_revenue(data) | ||
|
|
||
| assert len(result) == 1 | ||
| assert result[0]["revenue"] == 300.0 | ||
| assert result[0]["vat"] == 63.0 | ||
|
|
||
|
|
||
| def test_no_mutation(): | ||
| # TODO: feed in a list, run any transform on it, assert the original | ||
| # list is unchanged. This is the most important test in the file. | ||
| raise NotImplementedError | ||
| original_data = [ | ||
| {"product_name": "Laptop", "price": 100.0, "quantity": 1} | ||
| ] | ||
|
|
||
| data_to_transform = copy.deepcopy(original_data) | ||
| calculate_revenue(data_to_transform) | ||
| assert data_to_transform == original_data | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| https://sthyfstudentsdemo.blob.core.windows.net/week2-mareh-aboghanem/cleaned_sales.csv |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter_zero_quantity is not working because quantity comes out of the CSV as a string "0", not an integer 0, so "0" != 0 is always true and zero-quantity rows slip through. Wrap it in int() to fix this.