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 < 8000 meta property="og:image:height" content="600" />
[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

@ThemisKoutsellis

Description

@ThemisKoutsellis

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0