-
Notifications
You must be signed in to change notification settings - Fork 0
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
63 clean code and refactor into class excel to entities #70
63 clean code and refactor into class excel to entities #70
Conversation
Pull Request Test Coverage Report for Build 13112718684Details
💛 - Coveralls |
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.
Looks perfect, congrats! 🙂
Just a couple of comments for you to discuss with me if you agree or not.
Maybe it is a good idea to add testing for this class, but this I leave for you to decide if you want to do it in this PR or open a new issue and tackle it later.
|
||
|
||
class MasterdataExcelExtractor: | ||
DATA_TYPES = [ |
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.
You can use the Enum defined in bam_masterdata.metadata.definitions import DataType
. If you want to check if some value
is allowed by the data types, you just need to do:
value in [dt.value for dt in DataType]
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.
Changed thank you!
"OBJECT", | ||
] | ||
|
||
VALIDATION_RULES = { |
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.
Can you add a todo comment before this variable?
# TODO move these validation rules to a separate json
This is because I think we could have these mappings in a separate JSON to make it more readable. But you can leave it for another pr :)
from typing import TYPE_CHECKING, Any, Optional, Union | ||
|
||
import openpyxl | ||
from openpyxl.worksheet.worksheet import Worksheet |
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.
Ok, I checked the code and it seems Worksheet
is only used for typing. You can:
import re
from typing import TYPE_CHECKING, Any, Optional, Union
if TYPE_CHECKING:
from openpyxl.worksheet.worksheet import Worksheet
Then, you need to change in all the times a Worksheet
was typed in a function by "Worksheet"
, i.e., add the double-quotes, e.g.:
def get_last_non_empty_row(
self, sheet: "Worksheet", start_index: int
) -> Optional[int]:
The thing is that, if a class is only used for typing checks, then it does not need to be imported (and hence added to memory) every time the module is executed. That's why we have this TYPE_CHECKING and we just need to add an if condition + double quotes when typing the specific class.
Perfect, I will open a new issue for the testing after this pull request. |
This pull request includes changes to the
.vscode/settings.json
file to add a new debug configuration, and modifications to thebam_masterdata
module to refactor the way Excel data is extracted. The most important changes are summarized below:Debug Configuration Improvements:
.vscode/settings.json
: Added a new debug configuration for exporting to RDF and setjustMyCode
tofalse
to include library code in debugging. [1] [2]Code Refactoring:
bam_masterdata/cli/fill_masterdata.py
: Refactored to useMasterdataExcelExtractor
for extracting entities from Excel, replacing the previousexcel_to_entities
function. [1] [2]bam_masterdata/excel/__init__.py
: Added import forMasterdataExcelExtractor
to the module's__init__.py
file.