Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix #200: raise TypeError on unused kwargs #208

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion xrft/tests/test_xrft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dask.array as dsar

import scipy.signal as sps
import scipy.linalg as spl

import pytest
import numpy.testing as npt
Expand Down Expand Up @@ -202,6 +201,14 @@ def test_fft_4d(self):
np.fft.fftn(da_prime),
)

def test_fft_raises_on_unused_kwarg(self):
with pytest.raises(TypeError):
xrft.fft(None, dims=1)

def test_ifft_raises_on_unused_kwarg(self):
with pytest.raises(TypeError):
xrft.fft(None, dims=1)


class TestfftReal(object):
def test_fft_real_1d(self, test_data_1d):
Expand Down
17 changes: 7 additions & 10 deletions xrft/xrft.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import warnings
import operator
import sys
import functools as ft
from functools import reduce

import numpy as np
Expand All @@ -12,7 +10,6 @@
from dask import delayed

import scipy.signal as sps
import scipy.linalg as spl

from .detrend import detrend as _detrend
from pandas.api.types import is_numeric_dtype, is_datetime64_any_dtype
Expand Down Expand Up @@ -209,7 +206,7 @@ def _diff_coord(coord):
return np.diff(coord)
elif pd.api.types.is_datetime64_dtype(v0):
diff = np.diff(coord).astype("timedelta64[ns]").astype("f8")
diff = (diff/1e9) #convert back to seconds
diff = diff / 1e9 # convert back to seconds
return diff
else:
return np.diff(coord)
Expand Down Expand Up @@ -319,7 +316,7 @@ def fft(
true_amplitude=True,
chunks_to_segments=False,
prefix="freq_",
**kwargs,
real=None,
):
"""
Perform discrete Fourier transform of xarray data-array `da` along the
Expand Down Expand Up @@ -376,8 +373,8 @@ def fft(
if isinstance(dim, str):
dim = [dim]

if "real" in kwargs:
real_dim = kwargs.get("real")
if real is not None:
real_dim = real
warnings.warn(_real_flag_warning, FutureWarning)

if real_dim is not None:
Expand Down Expand Up @@ -490,7 +487,7 @@ def ifft(
chunks_to_segments=False,
prefix="freq_",
lag=None,
**kwargs,
real=None,
):
"""
Perform inverse discrete Fourier transform of xarray data-array `daft` along the
Expand Down Expand Up @@ -543,8 +540,8 @@ def ifft(
if isinstance(dim, str):
dim = [dim]

if "real" in kwargs:
real_dim = kwargs.get("real")
if real is not None:
real_dim = real
warnings.warn(_real_flag_warning, FutureWarning)

if real_dim is not None:
Expand Down
Loading