[BUG] OSError for non existent folder when running convert.py #35

Closed
opened 2025-03-16 10:29:12 +00:00 by nuluh · 1 comment
nuluh commented 2025-03-16 10:29:12 +00:00 (Migrated from github.com)

Bug Description

When convert.py ran, the script return error because the folder seems not pre-created.

Steps to Reproduce

  1. `cd data\QUGS
  2. Run py convert.py D:\thesis\data\dataset_B D;\thesis\data\converted\raw_B B

Expected Behavior

The script should have handler exception to automatically create the folder

Actual Behavior

The script doesn't have handler exception, hence give OSError

Error Logs

Traceback (most recent call last):
  File "data\QUGS\convert.py", line 68, in <module>
    main()
  File "data\QUGS\convert.py", line 64, in main
    create_damage_files(base_path, output_base, prefix)
  File "data\QUGS\convert.py", line 39, in create_damage_files        
    df[['Time', top_sensor]].to_csv(output_file_1, index=False)
  File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py", line 3720, in to_csv
    return DataFrameRenderer(formatter).to_csv(
  File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\formats\format.py", line 1189, in to_csv
    csv_formatter.save()
  File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\formats\csvs.py", line 241, in save
    with get_handle(
  File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\common.py", line 734, in get_handle
    check_parent_directory(str(handle))
  File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\common.py", line 597, in check_parent_directory
    raise OSError(rf"Cannot save file into a non-existent directory: '{parent}'")
OSError: Cannot save file into a non-existent directory: 'D;\thesis\data\converted\raw_B\DAMAGE_5'

Component

Data Processing

Version/Commit

8ab934f

Environment

No response

Additional Context

No response

### Bug Description When `convert.py` ran, the script return error because the folder seems not pre-created. ### Steps to Reproduce 1. `cd data\QUGS 2. Run `py convert.py D:\thesis\data\dataset_B D;\thesis\data\converted\raw_B B` ### Expected Behavior The script should have handler exception to automatically create the folder ### Actual Behavior The script doesn't have handler exception, hence give `OSError` ### Error Logs ```shell Traceback (most recent call last): File "data\QUGS\convert.py", line 68, in <module> main() File "data\QUGS\convert.py", line 64, in main create_damage_files(base_path, output_base, prefix) File "data\QUGS\convert.py", line 39, in create_damage_files df[['Time', top_sensor]].to_csv(output_file_1, index=False) File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper return func(*args, **kwargs) File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\generic.py", line 3720, in to_csv return DataFrameRenderer(formatter).to_csv( File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper return func(*args, **kwargs) File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\formats\format.py", line 1189, in to_csv csv_formatter.save() File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\formats\csvs.py", line 241, in save with get_handle( File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\common.py", line 734, in get_handle check_parent_directory(str(handle)) File "C:\Users\damar\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\io\common.py", line 597, in check_parent_directory raise OSError(rf"Cannot save file into a non-existent directory: '{parent}'") OSError: Cannot save file into a non-existent directory: 'D;\thesis\data\converted\raw_B\DAMAGE_5' ``` ### Component Data Processing ### Version/Commit 8ab934f ### Environment _No response_ ### Additional Context _No response_
nuluh commented 2025-03-16 11:19:28 +00:00 (Migrated from github.com)

The code seems creating output directories for damage scenarios in the main function, but it seems only creating directories for damage scenarios 1 to 4.
8ed1437d6d/data/QUGS/convert.py (L61-L62)
However, the create_damage_files function handles damage scenarios 1 to 6.

The code seems creating output directories for damage scenarios in the `main` function, but it seems only creating directories for damage scenarios 1 to 4. https://github.com/nuluh/thesis/blob/8ed1437d6d13d9e3785a8999fb405c9face932e2/data/QUGS/convert.py#L61-L62 However, the `create_damage_files` function handles damage scenarios 1 to 6.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nuluh/thesis#35