8000 Different results for numpy.fft.fft() when passing different types of argument (DataFrame, np.array) with the same valuesBUG: <Please write a comprehensive title after the 'BUG: ' prefix> · Issue #23873 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Different results for numpy.fft.fft() when passing different types of argument (DataFrame, np.array) with the same valuesBUG: <Please write a comprehensive title after the 'BUG: ' prefix> #23873

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
ThemisKoutsellis opened this issue Jun 5, 2023 · 4 comments
Labels

Comments

@ThemisKoutsellis
Copy link
ThemisKoutsellis commented Jun 5, 2023

Describe the issue:

Describe your issue.

From the attached CSV file, input_data.csv, I import the, say, test_list. Then, I create a pd.Dataframe to store my data in test_df.

from scipy import fft
import numpy as np

test_df = pd.DataFrame(index=range(len(test_list)), columns=['test'])
test_df['test'] = test_list

I want to calculate the FFT transform of the signal in test_df['test']. However, I get different results when I pass as input different types of arguments to the scipy.fft.fft().

Once I pass the signal as a nympy.array I get the plot #1.

dummy

Once I pass the signal as a pd.Dataframe I get the plot #2.

dummy

Both inputs, np.array and pd.DataFrame contain the same information.

From the problem definition the plot#2 seems to have a better physical interpretation.
However, it is not clear why I get different results.

May be it is a bug?

The code I use is below:

from scipy import fft
import numpy as np

test_df = pd.DataFrame(index=range(len(test_list)), columns=['test'])
test_df['test'] = test_list


########## PLOT 1: from Numpy  ##############

to_np = test_df['test'].to_numpy()
print(to_np)

fft_output = fft.fft(to_np)
power = np.abs(fft_output)
freq = numpy.fft.fftfreq(len(to_np))

mask = freq >= 0
freq = freq[mask]
power = power[mask]


plt.plot(freq, power)
plt.show()


########## PLOT 2: from pd.DataFrame  ##############

to_df = test_df['test'].to_frame()
print(to_df)

fft_output = numpy.fft.fft(to_df)
power = np.abs(fft_output)
freq = fft.fftfreq(len(to_df))


mask = freq >= 0
freq = freq[mask]
power = power[mask]


plt.plot(freq, power)
plt.show()

Reproduce the code example:

from scipy import fft
import numpy as np

test_df = pd.DataFrame(index=range(len(test_list)), columns=['test'])
test_df['test'] = test_list


########## PLOT 1: from Numpy  ##############

to_np = test_df['test'].to_numpy()
print(to_np)

fft_output = fft.fft(to_np)
power = np.abs(fft_output)
freq = numpy.fft.fftfreq(len(to_np))

mask = freq >= 0
freq = freq[mask]
power = power[mask]


plt.plot(freq, power)
plt.show()


########## PLOT 2: from pd.DataFrame  ##############

to_df = test_df['test'].to_frame()
print(to_df)

fft_output = numpy.fft.fft(to_df)
power = np.abs(fft_output)
freq = fft.fftfreq(len(to_df))


mask = freq >= 0
freq = freq[mask]
power = power[mask]


plt.plot(freq, power)
plt.show()

Error message:

No response

Runtime information:

1.23.5
3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:38:11)
[Clang 14.0.6 ]

Context for the issue:

No response

@rossbar
Copy link
Contributor
rossbar commented Jun 5, 2023

Thanks for reporting @ThemisKoutsellis . I'm going to close this in favor of scipy/scipy#18635 to reduce duplication.

@rossbar rossbar closed this as completed Jun 5, 2023
@ThemisKoutsellis
Copy link
Author
ThemisKoutsellis commented Jun 5, 2023

It seems that the problem is due to numpy, not scipy. May be you should close the other one. Sorry, for the duplicate!

@rossbar
Copy link
Contributor
rossbar commented Jun 5, 2023

It looks like you're using scipy's fft module, so I figured scipy was more appropriate. However, if you've done some additional digging then please feel free to close that and reopen this as you see fit!

@ThemisKoutsellis
Copy link
Author

In this version of issue I use numpy. fft_output = numpy.fft.fft(to_df) i tested both ways (scipy and numpy) and I after realized that it is a numpy issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0