Skip to content

Commit

Permalink
BUG: Set mutable default function_library in __init__() body
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-Stevens-Haas committed Jan 3, 2024
1 parent e641dce commit f737ae1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pysindy/feature_library/pde_library.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings
from itertools import product as iproduct
from typing import Optional

import numpy as np
from sklearn.utils.validation import check_is_fitted
Expand Down Expand Up @@ -85,9 +86,7 @@ class PDELibrary(BaseFeatureLibrary):

def __init__(
self,
function_library: BaseFeatureLibrary = PolynomialLibrary(
degree=3, include_bias=False
),
function_library: Optional[BaseFeatureLibrary] = None,
derivative_order=0,
spatial_grid=None,
temporal_grid=None,
Expand All @@ -110,7 +109,8 @@ def __init__(
self.num_trajectories = 1
self.differentiation_method = differentiation_method
self.diff_kwargs = diff_kwargs

if function_library is None:
self.function_library = PolynomialLibrary(degree=3, include_bias=False)
if derivative_order < 0:
raise ValueError("The derivative order must be >0")

Expand Down
7 changes: 4 additions & 3 deletions pysindy/feature_library/weak_pde_library.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings
from itertools import product as iproduct
from typing import Optional

import numpy as np
from scipy.special import binom
Expand Down Expand Up @@ -135,9 +136,7 @@ class WeakPDELibrary(BaseFeatureLibrary):

def __init__(
self,
function_library: BaseFeatureLibrary = PolynomialLibrary(
degree=3, include_bias=False
),
function_library: Optional[BaseFeatureLibrary] = None,
derivative_order=0,
spatiotemporal_grid=None,
interaction_only=True,
Expand Down Expand Up @@ -166,6 +165,8 @@ def __init__(
self.num_trajectories = 1
self.differentiation_method = differentiation_method
self.diff_kwargs = diff_kwargs
if function_library is None:
self.function_library = PolynomialLibrary(degree=3, include_bias=False)

if spatiotemporal_grid is None:
raise ValueError(
Expand Down

0 comments on commit f737ae1

Please sign in to comment.