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

ENH: allow complex type inference in astype/convert_objects #4895

Closed
Tracked by #7
jreback opened this issue Sep 20, 2013 · 3 comments · Fixed by #52855
Closed
Tracked by #7

ENH: allow complex type inference in astype/convert_objects #4895

jreback opened this issue Sep 20, 2013 · 3 comments · Fixed by #52855
Assignees
Labels
Complex Complex Numbers Dtype Conversions Unexpected or buggy dtype conversions Enhancement Needs Tests Unit test(s) needed to prevent regressions

Comments

@jreback
Copy link
Contributor

jreback commented Sep 20, 2013

astype/convert_objects should be able to do this type of coercion from string complex looking

In [45]: Series(['1.0+5j','1.5-3j']).apply(lambda x: np.complex(x))
Out[45]: 
0      (1+5j)
1    (1.5-3j)
dtype: complex128

http://stackoverflow.com/questions/18919699/python-pandas-complex-number/18919965#18919965

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Feb 18, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 1, 2015
@jbrockmendel jbrockmendel added the Complex Complex Numbers label Jul 6, 2018
@datapythonista datapythonista modified the milestones: Contributions Welcome, Someday Jul 8, 2018
@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions Complex Complex Numbers Dtype Conversions Unexpected or buggy dtype conversions Enhancement and removed Complex Complex Numbers Dtype Conversions Unexpected or buggy dtype conversions Enhancement Numeric Operations Arithmetic, Comparison, and Logical operations Needs Tests Unit test(s) needed to prevent regressions good first issue labels Apr 3, 2020
@mroeschke mroeschke removed this from the Someday milestone Oct 13, 2022
@abkosar
Copy link
Contributor

abkosar commented Feb 3, 2023

@mroeschke This looks a bit old, but is this still available to work on?

And the as_type method, is it pandas.Series.as_type or pandas.DataFrame.as_type?

Also I think convert_objects is deprecated and it is now convert_dtypes?

@rhshadrach rhshadrach added the Needs Tests Unit test(s) needed to prevent regressions label Feb 11, 2023
@rhshadrach
Copy link
Member

rhshadrach commented Feb 11, 2023

Looks like this work on main:

print(Series(['1.0+5j', '1.5-3j']).astype(complex))
# 0    1.0+5.0j
# 1    1.5-3.0j
# dtype: complex128

print(DataFrame(['1.0+5j', '1.5-3j']).astype(complex))
#           0
# 0  1.0+5.0j
# 1  1.5-3.0j

Marking this as needs tests for now. Maybe this was reported in another (duplicate) issue and closed purposefully? I would recommend searching the issue tracker and/or tests before adding them.

@srkds
Copy link
Contributor

srkds commented Apr 22, 2023

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complex Complex Numbers Dtype Conversions Unexpected or buggy dtype conversions Enhancement Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants