Skip to content

BUG: Pandas rolling removes imaginary part of complex #46619

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

Closed
3 tasks done
fdelaigue opened this issue Apr 3, 2022 · 3 comments
Closed
3 tasks done

BUG: Pandas rolling removes imaginary part of complex #46619

fdelaigue opened this issue Apr 3, 2022 · 3 comments
Labels
Complex Complex Numbers Duplicate Report Duplicate issue or pull request Enhancement Window rolling, ewma, expanding

Comments

@fdelaigue
Copy link

fdelaigue commented Apr 3, 2022

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
pd.DataFrame([1j,1+2j]).rolling(2).apply(lambda x: print(x) is None)

Output:
0   0
1   1
dtype: float64
	0
0	NaN
1	1

Issue Description

.rolling() casts complex128 values into float64, discarding the imaginary part.

Expected Behavior

.rolling() passes complex128 values as is without removing the imaginary part.

Expected Output:

import pandas as pd
pd.DataFrame([1j,1+2j]).rolling(2).apply(lambda x: print(x) is None)

0   0+1j
1   1+2j
dtype: complex128
	0
0	NaN
1	1

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.10.0.final.0
python-bits : 64
OS : Darwin
OS-release : 21.2.0
Version : Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 1.4.1
numpy : 1.21.5
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 60.2.0
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.1.1
pandas_datareader: 0.10.0
bs4 : 4.10.0
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : 0.55.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@fdelaigue fdelaigue added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 3, 2022
@simonjayhawkins
Copy link
Member

Thanks @fdelaigue for the report

.rolling() casts complex128 values into float64, discarding the imaginary part.

did you not get a warning?

/home/simon/miniconda3/envs/pandas-1.4.2/lib/python3.10/site-packages/pandas/core/window/rolling.py:348: ComplexWarning: Casting complex values to real discards the imaginary part
  values = ensure_float64(values)

relabeling as an enhancement request and not a bug report.

@simonjayhawkins simonjayhawkins added Enhancement and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 3, 2022
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Apr 3, 2022
@mroeschke mroeschke added Complex Complex Numbers Window rolling, ewma, expanding labels Apr 3, 2022
@fdelaigue
Copy link
Author

fdelaigue commented Apr 3, 2022

Yes indeed - forgot I was catching warnings so didn't see it.

Nonetheless, adding astype(np.complex64) still returns float64:
pd.DataFrame([1j,1+2j]).astype(np.complex64).rolling(2).apply(lambda x: print(x) is None)
Output:
`

0 0
1 1
dtype: float64

  0
NaN
1
`

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@lithomas1 lithomas1 added the Duplicate Report Duplicate issue or pull request label May 15, 2023
@lithomas1
Copy link
Member

This isssue is still not addressed, but I will close and move to #53214, since that one is more general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complex Complex Numbers Duplicate Report Duplicate issue or pull request Enhancement Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants