Skip to content

Commit 817ccad

Browse files
committed
align with pandas 1.5
1 parent 584fbb5 commit 817ccad

File tree

5 files changed

+41549
-6
lines changed

5 files changed

+41549
-6
lines changed

clarite/modules/analyze/regression/glm_regression.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .base import Regression
1919

2020
# GITHUB ISSUE #119: Regressions with Error after Multiprocessing release python > 3.8
21-
multiprocessing.get_start_method("fork")
21+
# multiprocessing.get_start_method("fork")
2222

2323

2424
class GLMRegression(Regression):
@@ -129,7 +129,9 @@ def __init__(
129129
# Use the order according to the categorical
130130
counts = self.data[self.outcome_variable].value_counts().to_dict()
131131

132-
categories = self.data[self.outcome_variable].cat.categories
132+
# Add sorted
133+
categories = sorted(self.data[self.outcome_variable].cat.categories)
134+
133135
# GITHUB ISSUES #115: Keep control as 0 and case as 1
134136
if categories[0] == "Case" and categories[1] == "Control":
135137
categories = sorted(categories, reverse=True)
@@ -138,6 +140,14 @@ def __init__(
138140

139141
codes, categories = zip(*enumerate(categories))
140142
self.data[self.outcome_variable].replace(categories, codes, inplace=True)
143+
144+
# After upgrade to Pandas >= 1.5 the replace stop to covert as float
145+
# if stay as category, when create y will create to columns and will invert the
146+
# beta signal.
147+
self.data[self.outcome_variable] = self.data[self.outcome_variable].astype(
148+
float
149+
)
150+
141151
self.description += (
142152
f"Binary Outcome (family = Binomial): '{self.outcome_variable}'\n"
143153
f"\t{counts[categories[0]]:,} occurrences of '{categories[0]}' coded as 0\n"

clarite/modules/analyze/regression/r_survey_regression.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import pandas as pd
55

6-
from clarite.internal.utilities import requires, _get_dtypes
6+
from clarite.internal.utilities import _get_dtypes, requires
77

8-
from .base import Regression
98
from ...survey import SurveyDesignSpec
9+
from .base import Regression
1010

1111

1212
class RSurveyRegression(Regression):
@@ -50,6 +50,8 @@ def __init__(
5050
min_n: int = 200,
5151
report_categorical_betas: bool = False,
5252
standardize_data: bool = False,
53+
encoding=None, # TODO: Error on call
54+
edge_encoding_info=None, # TODO: Error on call
5355
):
5456
# base class init
5557
# This takes in minimal regression params (data, outcome_variable, covariates) and
@@ -175,7 +177,8 @@ def run(self):
175177
# Source R script to define the function
176178
import rpy2.robjects as ro
177179
from rpy2.robjects import pandas2ri
178-
from .r_code.r_utilities import ewasresult2py, df_pandas2r
180+
181+
from .r_code.r_utilities import df_pandas2r, ewasresult2py
179182

180183
r_code_folder = Path(__file__).parent / "r_code"
181184
filename = str(r_code_folder / "ewas_r.R")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "clarite"
3-
version = "2.3.3"
3+
version = "2.3.4"
44
description = "CLeaning to Analysis: Reproducibility-based Interface for Traits and Exposures"
55
authors = ["Andre Rico <[email protected]>"]
66
license = "BSD-3-Clause"

tests/analyze/test_interaction_study.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import numpy as np
44
import pandas as pd
5+
56
import clarite
67

78
TESTS_PATH = Path(__file__).parent.parent
@@ -225,3 +226,57 @@ def test_interactions_nhanes_pairwise(data_NHANES):
225226
)
226227
assert (grouped_bonf == python_result_nobeta["LRT_pvalue_bonferroni"]).all()
227228
assert (grouped_fdr == python_result_nobeta["LRT_pvalue_fdr"]).all()
229+
230+
231+
def test_interaction_exe():
232+
nested_table = clarite.load.from_csv(
233+
"/Users/andrerico/HALL/Python_3_10/clarite-python/tests/test_data_files/nested_table.csv"
234+
)
235+
# Return same result if not change data type
236+
# list_bin = (
237+
# "female",
238+
# "black",
239+
# "mexican",
240+
# "other_hispanic",
241+
# "other_eth",
242+
# )
243+
# list_cat = (
244+
# "SDDSRVYR",
245+
# "SES_LEVEL",
246+
# )
247+
# list_cont = (
248+
# "BMXBMI",
249+
# "RIDAGEYR",
250+
# "LBXCOT",
251+
# "IRON_mg",
252+
# "DR1TSFAT",
253+
# "DRDSDT1",
254+
# )
255+
256+
# nested_table = clarite.modify.make_binary(data=nested_table, only=(list_bin))
257+
# nested_table = clarite.modify.make_categorical(data=nested_table, only=(list_cat))
258+
# nested_table = clarite.modify.make_continuous(data=nested_table, only=(list_cont))
259+
260+
e1 = "DR1TSFAT"
261+
e2 = "DRDSDT1"
262+
list_covariant = [
263+
"female",
264+
"black",
265+
"mexican",
266+
"other_hispanic",
267+
"other_eth",
268+
"SDDSRVYR",
269+
"BMXBMI",
270+
"SES_LEVEL",
271+
"RIDAGEYR",
272+
"LBXCOT",
273+
"IRON_mg",
274+
]
275+
retorno = clarite.analyze.interaction_study(
276+
data=nested_table,
277+
outcomes="LBXHGB",
278+
interactions=[(e1, e2)],
279+
covariates=list_covariant,
280+
)
281+
282+
assert 2 == 2

0 commit comments

Comments
 (0)