Repository navigation
Pandas 0.15 categorical handling - #59
Conversation
…hulz for producing the initial patch I worked off of here.)
… but this is easier than carefully checking each!
ed47ef6 to
d40b54e
Compare
There was a problem hiding this comment.
Not sure what the problem could be here.
|
@njsmith I think you can take the test from the original issue (untested): data = """survived", "died", "treated", "risk"
12, 3, "control", "low"
10, 2, "treated", "low"
6, 7, "control", "medium"
10, 3, "treated", "medium"
3, 6, "control", "high"
8, 2, "treated", "high"
"""
import pandas
import scipy.linalg;
import scipy.lib.lapack.calc_lwork;
scipy.linalg.calc_lwork = scipy.lib.lapack.calc_lwork #version creep bug: https://github.com/statsmodels/statsmodels/issues/2191
import statsmodels.api as sm #<-- this is the mark of a badly designed API: when you have a special subpackage just for your API
D = pd.read_csv(data)
def factor(series):
"coerce series to a categorical variable in one line"
"meant to be like R's factor() command"
series = series.astype("category")
series.cat.set_categories(set(series), inplace=True)
# ^ from http://pandas-docs.github.io/pandas-docs-travis/categorical.html#getting-data-in-out
return series
for C in ["treated", "risk"]:
D[C] = factor(D[C])
M = sm.GLM.from_formula("died ~ treated", D) |
|
nosy comment to get myself on the notification list |
|
Just a datapoint: This works with my code. It would be wonderful if the fix found its way into patsy soonish, it is difficult to get co-authors compile install things by hand rather than a simple "conda install"... |
|
@JanSchulz: I tried running the |
|
For some reason Travis is being super-slow, but the only change in my last commit was to a comment, and the version before that passed tests, so I guess I'll go ahead and merge this, and then if it breaks things we can clean that up after... |
Pandas 0.15 categorical handling
Okay, here's my attempt to work around the changes in categorical handling in pandas 0.15.
@JanSchulz: I would very much appreciate a review, since this is heavily based on your patch in #47 (plus some refactoring to try and fix a few more issues). The individual commits are logical chunks, so it might be easier to read that way then as one giant patch.
I'd also really appreciate if you could write down a self-contained test that triggers the issue in pandas-dev/pandas#9581, or at least enough of an example to let me trigger it? I'm pretty sure I fixed it, but I'm not sure how to write a test case for it...
@kousu: I don't fully understand the issues you described in #47 (comment) , so I'm not sure whether I've fixed them or not :-). (They did make me squint harder at the interaction between
C()and pandas categoricals, which helped me find a bug! But I don't think it was your bug.) If you happen to have the chance, I'd be interested in (a) whether installing this branch fixes your problems, (b) whether you could write a small self-contained test (i.e., avoidingread_csvand just callingpatsy.dmatrixorpatsy.dmatricesinstead of using statsmodels) that triggers the issues you were seeing, so either so I can debug further (if it's not fixed), or add a test case (if it is fixed, so it will stay fixed).