False-positive python:S5644 with Pandas.resample().mean()

  • What language is this for? Python
  • Which rule? S5644
  • Why do you believe it’s a false-positive/false-negative? Works in Python, type-checks in mypy/pyright
  • SonarLint v4.3.0, not connected
  • pandas 2.2.1
  • pandas-stubs 2.2.0.240218
from typing import reveal_type

import pandas as pd

times = pd.Series([0, 2, 4, 6, 8], dtype="timedelta64[ns]")
raw = pd.DataFrame({"value": [0, 2, 4, 6, 8]}, index=times)

print(raw)
resampled = raw.resample("1ns").mean()

print(resampled["value"])
reveal_type(resampled)

resampled is a DataFrame, so resampled["value"] works.

Hi @bers,

Thank you very much for reporting this issue. I have created this ticket to track our progress on the issue.

Best,

David