aws / aws/amazon-sagemaker-examples
Columns and DataType Not Explicitly Set on line 183 of utils.py
- Dominant language
- Jupyter Notebook
- Stars
- 11k
- Forks
- 7k
- Avg merge
- 8h 29m
- Merged PRs (30d)
- 8
Description
Hello!
I found an AI-Specific Code smell in your project.
The smell is called: Columns and DataType Not Explicitly Set
You can find more information about it in this paper: https://dl.acm.org/doi/abs/10.1145/3522664.3528620.
According to the paper, the smell is described as follows:
| **Problem** | If the columns are not selected explicitly, it is not easy for developers to know what to expect in the downstream data schema. If the datatype is not set explicitly, it may silently continue the next step even though the input is unexpected, which may cause errors later. The same applies to other data importing scenarios. |
| ------------- | :------------- |
| **Solution** | **It is recommended to set the columns and DataType explicitly in data processing.** |
| **Impact** | **Readability** |
Example:
```diff
### Pandas Column Selection
import pandas as pd
df = pd.read_csv('data.csv')
+ df = df[['col1', 'col2', 'col3']]
### Pandas Set DataType
import pandas as pd
- df = pd.read_csv('data.csv')
+ df = pd.read_csv('data.csv', dtype={'col1': 'str', 'col2': 'int', 'col3': 'float'})
```
You can find the code related to this smell in this link: https://github.com/aws/amazon-sagemaker-examples/blob/187e52fc3db844645b469cc35122ccbc188357a1/sagemaker_model_monitor/visualization/utils.py#L173-L193.
I also found instances of this smell in other files, such as:
File: https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/autogluon-tabular/container-training/inference.py#L90-L100 Line: 95
File: https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/autogluon-tabular/container-training/inference.py#L92-L102 Line: 97
File: https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/autogluon-tabular/container-training/inference.py#L127-L137 Line: 132
File: https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/autogluon-tabular/container-training/train.py#L54-L64 Line: 59
File: https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/autogluon-tabular/container-training/train.py#L214-L224 Line: 219
.
I hope this information is helpful!
Contributor guide
Research direction
Start with sagemaker_model_monitor/visualization/utils.py around lines 173-193, then inspect the listed inference.py and train.py locations. Identify the pandas data-import or processing calls at those lines and determine the intended columns and data types from each example; done means the affected calls set them explicitly without breaking the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- pandas, python
- Domain
- data, machine-learning
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100