Skip to content

gridpath_viz_capacity_total_plot Fails on Windows Due to Hard‑Coded Path Separator #1328

@yifang-zhu-pge

Description

@yifang-zhu-pge

Issue: gridpath_viz_capacity_total_plot Fails on Windows Due to Path Handling

Description

When running on Windows 11:

gridpath_viz_capacity_total_plot.exe --load_zone Zone1 --scenario test --show

the following error occurs:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\E80747\Workspace\gridpath_demo\venv\Scripts\gridpath_viz_capacity_total_plot.exe\__main__.py", line 6, in <module>
    sys.exit(main())
             ~~~~^^
  File "C:\Users\E80747\Workspace\gridpath_demo\venv\Lib\site-packages\viz\capacity_total_plot.py", line 109, in main
    conn = connect_to_database(db_path=parsed_args.database)
  File "C:\Users\E80747\Workspace\gridpath_demo\venv\Lib\site-packages\db\common_functions.py", line 34, in connect_to_database
    if not os.path.isfile(db_path):
           ~~~~~~~~~~~~~~^^^^^^^^^
TypeError: _path_isfile: path should be string, bytes, os.PathLike or integer, not NoneType

Analysis

The issue appears to be caused by the default argument in:

def connect_to_database(db_path="../db/io.db", timeout=5, detect_types=0)

On Windows, forward slashes (/) can be interpreted inconsistently, depending on context and how the executable wrapper resolves paths. In this case, the default value "../db/io.db" may not resolve correctly, resulting in db_path ultimately being None, which then causes os.path.isfile() to throw a TypeError.

Suggested Fix

Use pathlib.Path for cross-platform compatibility:

from pathlib import Path

def connect_to_database(
    db_path=Path("..") / "db" / "io.db",
    timeout=5,
    detect_types=0
):

This ensures automatic OS-specific path resolution and eliminates issues with path separators.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions