chore(code): Fix setting with copy warning
This commit is contained in:
parent
72e11a67d7
commit
157d437611
1 changed files with 16 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
from typing import cast
|
||||
|
||||
from pandas import DataFrame
|
||||
|
||||
|
||||
|
@ -7,20 +8,22 @@ def calculate_validities(
|
|||
) -> DataFrame:
|
||||
EXT_COL_NAME: str = "external_validity"
|
||||
INT_COL_NAME: str = "internal_validity"
|
||||
vd = df[(df["design"] == "quasi-experimental") | (df["design"] == "experimental")]
|
||||
cols = {EXT_COL_NAME: 0, INT_COL_NAME: 0}
|
||||
|
||||
vd[EXT_COL_NAME] = 0
|
||||
vd[INT_COL_NAME] = 0
|
||||
vd = df[
|
||||
(df["design"] == "quasi-experimental") | (df["design"] == "experimental")
|
||||
].copy()
|
||||
vd.assign(**cols)
|
||||
vd = cast(DataFrame, vd)
|
||||
|
||||
vd[repr_col] = vd[repr_col].fillna("")
|
||||
vd[method_col] = vd[method_col].fillna("")
|
||||
# needs to check national before subnational, subnational before local
|
||||
vd.loc[vd[repr_col].str.contains("national"), EXT_COL_NAME] = 5.0
|
||||
vd.loc[vd[repr_col].str.contains("regional"), EXT_COL_NAME] = 4.0
|
||||
vd.loc[vd[repr_col].str.contains("subnational"), EXT_COL_NAME] = 3.0
|
||||
vd.loc[vd[repr_col].str.contains("local"), EXT_COL_NAME] = 2.0
|
||||
|
||||
vd[method_col] = vd[method_col].fillna("")
|
||||
# needs to go lowest to highest in case of multiple mentioned approaches
|
||||
vd.loc[
|
||||
vd[method_col].str.contains("|".join(["OLS", "ordinary.least.square"])),
|
||||
|
@ -56,10 +59,12 @@ def calculate_validities(
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
import sys
|
||||
import load_data
|
||||
from pathlib import Path
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
import load_data
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
df = load_data.from_yml(Path(sys.argv[1]))
|
||||
|
@ -70,4 +75,8 @@ if __name__ == "__main__":
|
|||
output = StringIO()
|
||||
df.to_csv(output)
|
||||
output.seek(0)
|
||||
print(output.read())
|
||||
try:
|
||||
print(output.read())
|
||||
except BrokenPipeError:
|
||||
devnull = os.open(os.devnull, os.O_WRONLY)
|
||||
os.dup2(devnull, sys.stdout.fileno())
|
||||
|
|
Loading…
Reference in a new issue