Skip to content

Commit

Permalink
FEAT: Add utility to set a DataFrame to false. Eliminates bug that wi…
Browse files Browse the repository at this point in the history
…ll emerge in future Pandas when setting a dataframe to False without type casting, like df.loc[:] = False.
  • Loading branch information
genedan committed Dec 30, 2024
1 parent cde871e commit ef3ec71
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion faslr/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
TEMP_LDF_LIST
)

from faslr.utilities import df_set_false

from pandas import DataFrame

from PyQt6.QtCore import (
Expand Down Expand Up @@ -121,7 +123,7 @@ def __init__(
# boolean values to indicate which factors in the corresponding triangle should be excluded
# it is first initialized to be all False, indicating no factors excluded initially
self.excl_frame = self.link_frame.copy()
self.excl_frame.loc[:] = False
self.excl_frame = df_set_false(df=self.excl_frame)

# Get the position of a blank row to be inserted between the end of the triangle
# and before the development factors
Expand Down
6 changes: 5 additions & 1 deletion faslr/triangle_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
VALUE_STYLE
)

from faslr.utilities import (
df_set_false
)

from PyQt6.QtCore import (
Qt,
QVariant
Expand Down Expand Up @@ -53,7 +57,7 @@ def __init__(
self.n_rows = self.rowCount()
self.n_columns = self.columnCount()
self.excl_frame = self._data.copy()
self.excl_frame.loc[:] = False
self.excl_frame = df_set_false(df=self.excl_frame)

def data(
self,
Expand Down
4 changes: 4 additions & 0 deletions faslr/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
subset_dict
)

from faslr.utilities.dataframe import (
df_set_false
)

from faslr.utilities.sample import (
auto_bi_olep,
load_sample,
Expand Down
21 changes: 21 additions & 0 deletions faslr/utilities/dataframe.py
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

0 comments on commit ef3ec71

Please sign in to comment.