Skip to content

Commit

Permalink
do not assign default value to sparse dtypes since that knowledge is …
Browse files Browse the repository at this point in the history
…already baked-in (#1278, #1370)

Signed-off-by: Derin Walters <[email protected]>
  • Loading branch information
derinwalters committed Oct 6, 2023
1 parent 9b32644 commit db4870b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pandera/backends/pandas/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ def run_checks(self, check_obj, schema) -> List[CoreCheckResult]:

def set_default(self, check_obj, schema):
"""Sets the ``schema.default`` value on the ``check_obj``"""
if is_field(check_obj):
# Ignore sparse dtype as it can't assign default value directly
if is_field(check_obj) and not isinstance(check_obj.dtype, pd.SparseDtype):
check_obj.fillna(schema.default, inplace=True)
else:
elif not is_field(check_obj) and not isinstance(check_obj[schema.name].dtype, pd.SparseDtype):
check_obj[schema.name].fillna(schema.default, inplace=True)

return check_obj
Expand Down

0 comments on commit db4870b

Please sign in to comment.