from pandas import DataFrame, Series
# This function prunes the dataframe rows to those meeting specified criteria
def prune_to_wanted_rows(st_df: DataFrame, recency_date: str) -> DataFrame:
st_df = st_df[ # pyright error message (see below) here
(st_df["assetType"] == "ore")
& (st_df["priceCurrency"] == "USD")
& (st_df["endDate"] >= recency_date)
# other boolean expressions omitted for brevity
]
return st_df
The error message, all on the one line, with hyphens here replacing some spaces, is:
Expression of type "Series | Unknown | DataFrame" is incompatible with declared type "DataFrame"------Type "Series | Unknown | DataFrame" is incompatible with type "DataFrame"------Type "Series" is incompatible with "DataFrame"
I think this is only a problem because the error message is ugly. I can suppress it with # pyright: ignore
and the code works as intended. I don't (yet) see a type incompatibility, but is there a sense in which pyright is "right"?
Changing st_df = st_df[
to
st_def = st_df.loc[
prevents the error message.