Skip to content

Fix logical bugs and prepare for Pandas 3.0 compatibility#7

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-adifgraph-date-parsing
Draft

Fix logical bugs and prepare for Pandas 3.0 compatibility#7
Copilot wants to merge 2 commits intomainfrom
copilot/fix-adifgraph-date-parsing

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 16, 2026

Fixes several logical bugs in date parsing and exception handling, while preparing the codebase for Pandas 3.0 API changes.

Changes

Logical bug fixes:

  • Fixed empty DataFrame check: len(df) < 0len(df) == 0 (length cannot be negative)
  • Fixed exception handling: except A or B:except (A, B): (incorrect Python syntax only caught first exception)

Date parsing robustness:

  • Added errors='coerce' to pd.to_datetime() to convert invalid dates to NaT instead of raising
  • Added dropna(subset=['QSO_DATE']) after parsing to filter out invalid dates

Pandas 3.0+ compatibility:

  • Replaced deprecated is_period_dtype() with isinstance(dtype, pd.PeriodDtype) per pandas deprecation warning

Example

# Before: would crash on invalid dates
df['QSO_DATE'] = pd.to_datetime(df['QSO_DATE'])

# After: gracefully handles invalid dates
df['QSO_DATE'] = pd.to_datetime(df['QSO_DATE'], errors='coerce')
df = df.dropna(subset=['QSO_DATE'])

Affected Files

  • adiftools/adifgraph.py: 3 functions (monthly_qso, band_percentage, monthly_band_qso)
  • adiftools/adiftools.py: 4 import statements
Original prompt

目的:
Pandas 3.0 への更新で互換性問題が起きないよう、リポジトリ内のいくつかの潜在的な不具合と日付パースの堅牢性を修正するPRを作成します。主に以下を行います。

修正内容(ファイル単位):

  1. adiftools/adifgraph.py
  • 空 DataFrame 判定のバグ修正:
    • if len(df) < 0:if len(df) == 0: に変更(monthly_qso, band_percentage, monthly_band_qso の全該当箇所)。
  • 日付パースの堅牢化:
    • pd.to_datetime(df['QSO_DATE'])pd.to_datetime(df['QSO_DATE'], errors='coerce') に変更して、パースできない値を NaT にする。
    • NaT を含む行を適切に除去(dropna(subset=['QSO_DATE']))して以降の操作でエラーにならないようにする。
  • Period 型判定を安全に:
    • from pandas.api.types import PeriodDtype + isinstance(df['QSO_DATE'].dtype, PeriodDtype) の���わりに from pandas.api.types import is_period_dtype を使い、if is_period_dtype(df['QSO_DATE'].dtype): とする。これにより pandas の内部表現に依存し過ぎない判定にする。
  1. adiftools/adiftools.py
  • 例外捕捉句の修正:
    • except ModuleNotFoundError or ImportError:except (ModuleNotFoundError, ImportError): に修正(複数箇所)。

追加説明:

  • これらの修正は pandas の API 変更に備えた堅牢化と、既存の明らかな論理ミスの修正が目的です。pandas 3.0 固有の大きな互換破壊が直ちに必要な修正は見当たりませんが、日付パースがより厳密になる可能性に備えて errors='coerce' を入れておくことで安全性を高めます。
  • テストや CI については別 PR で pandas 2.x / 3.x の matrix テストを追加することを推奨しますが、本PRではまず最小のコード修正に留めます。

変更ファイル:

  • adiftools/adifgraph.py
  • adiftools/adiftools.py

期待する結果:

  • pandas 3.0 環境にアップデートしても、日付パース周りで例外が発生しにくくなり、空 DataFrame の検出ロジックと import 例外処理のバグが解消される。

備考:

  • 画像は無し。
  • 変更は小規模で後方互換性を保つように行います。

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Fix empty DataFrame check: Changed `if len(df) < 0:` to `if len(df) == 0:` in adifgraph.py
- Fix exception handling: Changed `except ModuleNotFoundError or ImportError:` to `except (ModuleNotFoundError, ImportError):` in both files
- Add robust date parsing with `errors='coerce'` to handle invalid dates
- Add dropna to remove NaT values after date parsing
- Replace deprecated is_period_dtype with isinstance check using pd.PeriodDtype

Co-authored-by: JS2IIU-MH <146515386+JS2IIU-MH@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix potential bugs and improve date parsing in adifgraph.py Fix logical bugs and prepare for Pandas 3.0 compatibility Feb 16, 2026
Copilot AI requested a review from JS2IIU-MH February 16, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants