8000 Different results for scipy.fft.fft() when passing different types of argument (DataFrame, np.array) with the same values · Issue #18635 · scipy/scipy · GitHub
[go: up one dir, main page]

Skip to content
Different results for scipy.fft.fft() when passing different types of argument (DataFrame, np.array) with the same values  #18635
@ThemisKoutsellis

Description

@ThemisKoutsellis

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 = 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 = 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()

Reproducing 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 = 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 = 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()

SciPy/NumPy/Python version and system information

1.10.1 1.23.5 sys.version_info(major=3, minor=9, micro=16, releaselevel='final', serial=0)
Build Dependencies:
  blas:
    detection method: cmake
    found: true
    include directory: unknown
    lib directory: unknown
    name: OpenBLAS
    openblas configuration: unknown
    pc file directory: unknown
    version: 0.3.18
  lapack:
    detection method: cmake
    found: true
    include directory: unknown
    lib directory: unknown
    name: OpenBLAS
    openblas configuration: unknown
    pc file directory: unknown
    version: 0.3.18
Compilers:
  c:
    commands: cc
    linker: ld64
    name: clang
    version: 13.1.6
  c++:
    commands: c++
    linker: ld64
    name: clang
    version: 13.1.6
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 0.29.33
  fortran:
    commands: gfortran
    linker: ld64
    name: gcc
    version: 12.1.0
  pythran:
    include directory: /private/var/folders/_f/lyvxf0v13gs7984d7sf7j83c0000gn/T/pip-build-env-oi1yv7w9/overlay/lib/python3.9/site-packages/pythran
    version: 0.12.1
Machine Information:
  build:
    cpu: aarch64
    endian: little
    family: aarch64
    system: darwin
  cross-compiled: false
  host:
    cpu: aarch64
    endian: little
    family: aarch64
    system: darwin
Python Information:
  path: /private/var/folders/_f/lyvxf0v13gs7984d7sf7j83c0000gn/T/cibw-run-re4zhq8x/cp39-macosx_arm64/build/venv/bin/python
  version: '3.9'

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0