Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of a Series[int] with a complex returns Series[unknown] #1098

Open
loicdiridollou opened this issue Jan 14, 2025 · 3 comments
Open
Labels
good first issue Series Series data structure

Comments

@loicdiridollou
Copy link
Contributor

import pandas as pd

c = 1 + 1j
s = pd.Series([1.0, 2.0, 3.0])

check(assert_type(s + c, "pd.Series[complex]"), pd.Series) ■ "assert_type" mismatch: expected "Series[complex]" but received "Series[unknown]"

Please complete the following information:

OS: Darwin
OS Version [e.g. 22]: 15.2
python version: 3.12.7
version of type checker: mypy latest
version of installed pandas-stubs: latest
Additional context

version of pandas: 2.2.3
mypy option: strict=False

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jan 14, 2025

Need to update the various operators to handle arguments that are complex

@loicdiridollou
Copy link
Contributor Author

loicdiridollou commented Jan 14, 2025

Also another issue about the __sub__ and __mul__ operators between two Series[int]:

s = pd.Series([0, 1, -10])
s2 = pd.Series([7, -5, 10])

check(assert_type(s - s2, "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s * s2,  "pd.Series[int]"), pd.Series, np.integer)
check(assert_type(s / s2, "pd.Series[float]"), pd.Series, np.float64)

@loicdiridollou
Copy link
Contributor Author

s1 = pd.Series([0, 1, 2, 3])
s2 = pd.Series([-1, 2, -3, 4])
df1 = pd.DataFrame([[0, 1], [-2, 3], [4, -5], [6, 7]])
n1 = np.array([[0, 1], [1, 2], [-1, -1], [2, 0]])
check(assert_type(s1.dot(s2), Scalar), np.int64)
check(assert_type(s1 @ s2, Scalar), np.int64)
check(assert_type(s1.dot(df1), "pd.Series[int]"), pd.Series, np.int64)
check(assert_type(s1.dot(s2), Scalar), np.integer)
check(assert_type(s1 @ s2, Scalar), np.integer)
check(assert_type(s1.dot(df1), "pd.Series[int]"), pd.Series, np.integer)  # should be float here as we don't know the type of the df

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Series Series data structure
Projects
None yet
Development

No branches or pull requests

2 participants