gempy-project / gempy

GemPy is an open-source, Python-based 3-D structural geological modeling software, which allows the implicit (i.e. automatic) creation of complex geological models from interface and orientation data. It also offers support for stochastic modeling to address parameter and model uncertainties.
https://gempy.org
European Union Public License 1.2
965 stars 232 forks source link

Columns and DataType Not Explicitly Set on line 99 of input_manipulation.py #811

Closed CodeSmileBot closed 5 months ago

CodeSmileBot commented 1 year ago

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:


### 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/cgre-aachen/gempy/blob/0a4bb6280e51c8bd8dcbb1349939bbfb457c38b7/gempy/utils/input_manipulation.py#L89-L109.

I also found instances of this smell in other files, such as:

File: https://github.com/cgre-aachen/gempy/blob/master/examples/integrations/gempy_subsurface.py#L94-L104 Line: 99 File: https://github.com/cgre-aachen/gempy/blob/master/gempy/addons/gempy_to_rexfile.py#L260-L270 Line: 265 File: https://github.com/cgre-aachen/gempy/blob/master/gempy/addons/map2gempy.py#L52-L62 Line: 57 File: https://github.com/cgre-aachen/gempy/blob/master/gempy/addons/map2gempy.py#L71-L81 Line: 76 File: https://github.com/cgre-aachen/gempy/blob/master/gempy/addons/map2gempy.py#L62-L72 Line: 67 .

I hope this information is helpful!