-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
Added functionality to import perfect Excel #3059
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8e99e07
added methods to import excel
IamEzio 4b82e9f
updated get_file_type method
IamEzio bb303bd
cleanup
IamEzio be2740b
nit
IamEzio 9bd6bca
review update
IamEzio 5603324
nit
IamEzio 7b69371
Merge branch 'develop' into perfect-excel
IamEzio 411b764
renamed method
IamEzio d8a4149
Merge branch 'perfect-excel' of https://github.com/IamEzio/mathesar i…
IamEzio bcc5325
renamed methods (data -> records)
IamEzio File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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 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,45 @@ | ||
import pandas | ||
|
||
from db.tables.operations.alter import update_pk_sequence_to_latest | ||
from mathesar.database.base import create_mathesar_engine | ||
from db.records.operations.insert import insert_records_from_excel | ||
from db.tables.operations.create import create_string_column_table | ||
from db.tables.operations.drop import drop_table | ||
from mathesar.imports.utils import get_alternate_column_names, process_column_names | ||
from psycopg2.errors import IntegrityError, DataError | ||
|
||
from mathesar.state import reset_reflection | ||
|
||
|
||
def insert_records_from_dataframe(name, schema, column_names, engine, comment, dataframe): | ||
table = create_string_column_table( | ||
name=name, | ||
schema=schema.name, | ||
column_names=column_names, | ||
engine=engine, | ||
comment=comment, | ||
) | ||
|
||
insert_records_from_excel( | ||
table, | ||
engine, | ||
dataframe, | ||
) | ||
return table | ||
|
||
|
||
def create_db_table_from_excel_data_file(data_file, name, schema, comment=None): | ||
db_name = schema.database.name | ||
engine = create_mathesar_engine(db_name) | ||
dataframe = pandas.read_excel(data_file.file.path) | ||
column_names = process_column_names(dataframe.columns) | ||
try: | ||
table = insert_records_from_dataframe(name, schema, column_names, engine, comment, dataframe) | ||
update_pk_sequence_to_latest(engine, table) | ||
except (IntegrityError, DataError): | ||
drop_table(name=name, schema=schema.name, engine=engine) | ||
column_names_alt = get_alternate_column_names(column_names) | ||
table = insert_records_from_dataframe(name, schema, column_names_alt, engine, comment, dataframe) | ||
|
||
reset_reflection(db_name=db_name) | ||
return table |
This file contains 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 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.
This file contains 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 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
Oops, something went wrong.
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.
Nice and clear 👍