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 typing import cast
|
||||||
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,20 +8,22 @@ def calculate_validities(
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
EXT_COL_NAME: str = "external_validity"
|
EXT_COL_NAME: str = "external_validity"
|
||||||
INT_COL_NAME: str = "internal_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 = df[
|
||||||
vd[INT_COL_NAME] = 0
|
(df["design"] == "quasi-experimental") | (df["design"] == "experimental")
|
||||||
|
].copy()
|
||||||
|
vd.assign(**cols)
|
||||||
vd = cast(DataFrame, vd)
|
vd = cast(DataFrame, vd)
|
||||||
|
|
||||||
vd[repr_col] = vd[repr_col].fillna("")
|
vd[repr_col] = vd[repr_col].fillna("")
|
||||||
|
vd[method_col] = vd[method_col].fillna("")
|
||||||
# needs to check national before subnational, subnational before local
|
# 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("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("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("subnational"), EXT_COL_NAME] = 3.0
|
||||||
vd.loc[vd[repr_col].str.contains("local"), EXT_COL_NAME] = 2.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
|
# needs to go lowest to highest in case of multiple mentioned approaches
|
||||||
vd.loc[
|
vd.loc[
|
||||||
vd[method_col].str.contains("|".join(["OLS", "ordinary.least.square"])),
|
vd[method_col].str.contains("|".join(["OLS", "ordinary.least.square"])),
|
||||||
|
@ -56,10 +59,12 @@ def calculate_validities(
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import load_data
|
|
||||||
from pathlib import Path
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import load_data
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
df = load_data.from_yml(Path(sys.argv[1]))
|
df = load_data.from_yml(Path(sys.argv[1]))
|
||||||
|
@ -70,4 +75,8 @@ if __name__ == "__main__":
|
||||||
output = StringIO()
|
output = StringIO()
|
||||||
df.to_csv(output)
|
df.to_csv(output)
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
|
try:
|
||||||
print(output.read())
|
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