-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Distance File: Don't accept dropped .xlsx files #6601
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,8 @@ def open_file(self): | |
err = str(exc) | ||
self.Error.invalid_file(" \n"[len(err) > 40] + err) | ||
else: | ||
# If you add any other checks before accepting the file, | ||
# you should probably mirror them in canDropFile | ||
if distances.shape[0] != distances.shape[1]: | ||
self.Error.non_square_matrix() | ||
else: | ||
|
@@ -158,7 +160,14 @@ def parametersFromFile(self, path): | |
return {"recent_paths": stored_recent_paths_prepend(self.WIDGET, r)} | ||
|
||
def canDropFile(self, path: str) -> bool: | ||
return os.path.splitext(path)[1].lower() in (".dst", ".xlsx") | ||
if os.path.splitext(path)[0] == ".dst": | ||
return True | ||
try: | ||
distances = DistMatrix.from_file(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may take too long for big files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the file dimension again? Can you tell me which file it was - or send it? I tried 600x1000 and takes a few seconds. What I discovered was that, unfortunately, most time is spent in opening the Excel file. Hence, the File widget will take more or less the same time as well. Of course, with this PR, the file is read twice and we must prevent this. I'm considering decorating functions that open excel files with a lru cache of size 1 that would remember the last read excel workbook - of course checking not only the file name but also the timestamp. In this way - and given that opening the file takes majority of time - the time spent in owdistancefile would be saved in owfile because it would reuse the workbook object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was 1000x1000 .xlsx. |
||
except Exception: # pylint: disable=broad-except | ||
return False | ||
else: | ||
return distances.shape[0] == distances.shape[1] | ||
janezd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
if __name__ == "__main__": # pragma: no cover | ||
|
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 could keep the old condition (only .dst) for better performance.