-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Add utility to set a DataFrame to false. Eliminates bug that wi…
…ll emerge in future Pandas when setting a dataframe to False without type casting, like df.loc[:] = False.
- Loading branch information
Showing
4 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Contains commonly-used DataFrame-related routines. | ||
""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from pandas import DataFrame | ||
|
||
def df_set_false(df: DataFrame) -> DataFrame: | ||
""" | ||
Sets an entire DataFrame to False. Used in situations where we want a triangle of booleans where | ||
we first make a copy of another DataFrame full of data (like paid loss) in order to preserve parts of its metadata | ||
(accident years, development periods, etc.). | ||
""" | ||
|
||
df = df.astype(bool) | ||
df.loc[:] = False | ||
|
||
return df |