Thanks to visit codestin.com
Credit goes to github.com

Skip to content

COMPAT: Change khcomplex64/128_t typedefs #54375

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

Merged
merged 10 commits into from
Aug 3, 2023

Conversation

mroeschke
Copy link
Member

xref numpy/numpy#24085

suggestion by @seberg

@mroeschke mroeschke added the Compat pandas objects compatability with Numpy or Python functions label Aug 2, 2023
@mroeschke mroeschke requested a review from WillAyd as a code owner August 2, 2023 17:06
@mroeschke mroeschke added this to the 2.1 milestone Aug 2, 2023
@lithomas1
Copy link
Member

@mroeschke
Looks like some failures

FAILED pandas/tests/io/formats/test_printing.py::test_ser_df_with_complex_nans[True-data6-output6] - AssertionError
FAILED pandas/tests/io/formats/test_printing.py::test_ser_df_with_complex_nans[False-data6-output6] - AssertionError

typedef struct {
float real;
float imag;
} khcomplex64_t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} khcomplex64_t;
} khcomplex64_t;

Just a minor readability thing if you have to edit again. We should probably run this whole file through clang-format in a separate PR / CI

} khcomplex64_t;
typedef struct {
double real;
double imag;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this change anything on platforms where float/double aren't 32/64 bits? (which i guess we have zero testing for so not a huge deal)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. It appears in numpy/numpy#24085 in numpy/core/include/numpy/npy_math.h numpy also defines real/imag components as doubles

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the misnomer is to call these complex64 and complex128. The C99 standard has float complex and double complex types, but nothing that is a fixed width

See also https://stackoverflow.com/questions/2524737/fixed-size-floating-point-types#2524933

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess technically float32/float64 are sized aliases under the assumption they refer to float/double, but in practice the assumption seems so strong that I doubt it matters.

I am very puzzled about the change though, this is exactly what it was after all, and I don't think C cares about type aliases (even if there was interaction anywhere). I am wondering if the include <numpy/arrayobject.h> somehow is involved, but I don't see why it should be either?

I assume the value stored is correct here and just the printing somehow thinks it is printing a NaN?

@mroeschke
Copy link
Member Author

Can't reproduce this locally, but it seems that float real of complex(1.2, nan) is returning NaN instead of 1.2. Any ideas @WillAyd

@lithomas1
Copy link
Member

I think it might be a Python 3.12 issue. The regular numpy dev build doesn't fail.

@mroeschke
Copy link
Member Author

I think it might be a Python 3.12 issue. The regular numpy dev build doesn't fail.

I think numpy dev has cached dependencies so maybe the changes haven't caught up

@mroeschke
Copy link
Member Author

Looks like this change subtly changed how maybe_convert_objects infers complex scalars, but given that the failing test is a net new fix in 2.1 and the failure is an edge case with nan, I think the status quo is better that the behavior in 2.0 so merging as is.

@mroeschke mroeschke merged commit 0d0073a into pandas-dev:main Aug 3, 2023
@mroeschke mroeschke deleted the compat/np/imag branch August 3, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants