Ntsika Gajula#4
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements solutions to 6 programming questions in analytics.py covering list processing, dictionary operations, and inventory management logic, along with a test suite in test_inventory.py for the inventory status function.
Key Changes:
- Implemented 5 core functions:
filter_sales_above_threshold,count_product_codes,calculate_moving_average,get_top_seller, andmerge_inventory - Implemented
check_inventory_statusfunction with multi-condition logic tree for inventory analysis - Created comprehensive unit tests for the inventory status function in
test_inventory.py
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| analytics.py | Implemented 6 functions for data analytics including sales filtering, product code counting, moving averages, top seller identification, inventory merging, and inventory status checking |
| test_inventory.py | Added unit test suite with 6 test methods covering various scenarios for check_inventory_status function |
| pycache/analytics.cpython-313.pyc | Python bytecode cache file generated from analytics.py compilation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for product, quantity in warehouse_a: | ||
| if product in merged_inventory: | ||
| merged_inventory[product] += quantity | ||
| else: | ||
| merged_inventory[product] = quantity | ||
| for product, quantity in warehouse_b: |
There was a problem hiding this comment.
This line iterates over dictionary keys only, not key-value pairs. When iterating with for product, quantity in warehouse_a:, Python only yields keys, causing a ValueError: too many values to unpack. Use for product, quantity in warehouse_a.items(): to correctly iterate over key-value pairs.
| for product, quantity in warehouse_a: | |
| if product in merged_inventory: | |
| merged_inventory[product] += quantity | |
| else: | |
| merged_inventory[product] = quantity | |
| for product, quantity in warehouse_b: | |
| for product, quantity in warehouse_a.items(): | |
| if product in merged_inventory: | |
| merged_inventory[product] += quantity | |
| else: | |
| merged_inventory[product] = quantity | |
| for product, quantity in warehouse_b.items(): |
| merged_inventory[product] += quantity | ||
| else: | ||
| merged_inventory[product] = quantity | ||
| for product, quantity in warehouse_b: |
There was a problem hiding this comment.
This line iterates over dictionary keys only, not key-value pairs. When iterating with for product, quantity in warehouse_b:, Python only yields keys, causing a ValueError: too many values to unpack. Use for product, quantity in warehouse_b.items(): to correctly iterate over key-value pairs.
| for product, quantity in warehouse_b: | |
| for product, quantity in warehouse_b.items(): |
| """ | ||
| QUESTION 1 | ||
| ---------------------------------------- | ||
| Given a list of sales amounts (integers), return a NEW list containing | ||
| only values above the threshold. | ||
|
|
||
| Example: filter_sales_above_threshold([100, 250, 75, 300], 150) → [250, 300] | ||
|
|
||
| Example: filter_sales_above_threshold([100, 250, 75, 300], 150) → [250, 300] | ||
|
|
||
| Logic: | ||
| - Do NOT modify the original list | ||
| - Return empty list if no values qualify | ||
| - Use a loop or list comprehension | ||
| """ | ||
| # TODO: Write your code here | ||
| pass | ||
| Logic: | ||
| - Do NOT modify the original list | ||
| - Return empty list if no values qualify | ||
| - Use a loop or list comprehension | ||
| """ | ||
| # TODO: Write your code here | ||
| for sale in sales: | ||
| if sale < threshold: | ||
| sales.remove(sale) | ||
| return sales | ||
|
|
||
|
|
||
| def count_product_codes(codes: list, prefix: str): |
There was a problem hiding this comment.
Inconsistent indentation: The code uses 3 spaces for indentation in some places and 4 spaces in others. Python code should consistently use 4 spaces per indentation level according to PEP 8. Update all indentation to use 4 spaces consistently throughout the file.
| # TODO: Write your code here | ||
| count = 0 | ||
| for code in codes: | ||
| if prefix in code: |
There was a problem hiding this comment.
This uses substring matching (prefix in code) instead of checking if the code starts with the prefix. This will incorrectly match codes where the prefix appears anywhere in the string. Use code.startswith(prefix) instead to match only codes that START with the prefix as specified in the requirements.
| if prefix in code: | |
| if code.startswith(prefix): |
| """ | ||
| # TODO: Write your code here | ||
| if stock_level < 0 or reorder_point < 0 or max_capacity < 0 or daily_sales < 0: | ||
| return "Invalid Input" |
There was a problem hiding this comment.
Missing validation for stock_level > max_capacity as specified in the docstring logic tree. According to the requirements, this condition should return "Invalid Input". Add this check: if stock_level > max_capacity: return "Invalid Input" after the existing negative value check.
| return "Invalid Input" | |
| return "Invalid Input" | |
| if stock_level > max_capacity: | |
| return "Invalid Input" |
| def test_input_validity(self): | ||
| self.assertEqual(check_inventory_status(-5, 50, 100, 10), "Invalid Input") | ||
| self.assertEqual(check_inventory_status(55, -50, 100, 10), "Invalid Input") | ||
| self.assertEqual(check_inventory_status(55, 50, -100, 10), "Invalid Input") | ||
| self.assertEqual(check_inventory_status(55, 50, 100, -10), "Invalid Input") |
There was a problem hiding this comment.
Missing test case for the validation rule "If stock_level > max_capacity: return 'Invalid Input'". Add a test case such as: self.assertEqual(check_inventory_status(150, 50, 100, 10), "Invalid Input") to ensure this validation condition is covered.
| for sale in sales: | ||
| if sale < threshold: | ||
| sales.remove(sale) | ||
| return sales |
There was a problem hiding this comment.
This implementation modifies the original list, which violates the requirement in the docstring: "Do NOT modify the original list". Using sales.remove(sale) modifies the input list and also causes incorrect behavior because modifying a list while iterating over it leads to skipped elements. Use list comprehension instead: return [sale for sale in sales if sale > threshold]
| for sale in sales: | |
| if sale < threshold: | |
| sales.remove(sale) | |
| return sales | |
| return [sale for sale in sales if sale > threshold] |
| if not sales_data: | ||
| return "No Data" | ||
| highest_sales = 0 | ||
| for name, sales in sales_data: |
There was a problem hiding this comment.
This line iterates over dictionary keys only, not key-value pairs. When iterating over a dictionary directly with for name, sales in sales_data:, Python only yields keys, causing a ValueError: too many values to unpack. Use for name, sales in sales_data.items(): to correctly iterate over key-value pairs.
| highest_sales = 0 | ||
| for name, sales in sales_data: | ||
| if sales > highest_sales: | ||
| highest_sales = sales | ||
| top_seller = name |
There was a problem hiding this comment.
The function can return without top_seller being defined. If sales_data contains only items with sales values of 0 or negative, top_seller will never be assigned. Additionally, the logic doesn't handle ties alphabetically as specified in the docstring. Initialize top_seller = None before the loop and handle the tie-breaking requirement properly.
| highest_sales = 0 | |
| for name, sales in sales_data: | |
| if sales > highest_sales: | |
| highest_sales = sales | |
| top_seller = name | |
| highest_sales = float('-inf') | |
| top_seller = None | |
| for name, sales in sales_data.items(): | |
| if sales > highest_sales: | |
| highest_sales = sales | |
| top_seller = name | |
| elif sales == highest_sales: | |
| if top_seller is None or name < top_seller: | |
| top_seller = name |
No description provided.