You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: I'm not sure what the behavior with float should be. There is also the possibility to allow QMLE for simplex/compositional data.
import statsmodels.formula.api as sm
import pandas as pd
df = pd.DataFrame({"A": [0., 1.1, 0, 0, 1.1], "B": [0, 1, 0, 1, 1]})
result = sm.mnlogit(formula="A ~ B", data=df).fit()
>>> result.summary()
ynames = ['='.join([yname, name]) for name in ynames]
TypeError: sequence item 1: expected str instance, numpy.float64 found
>>> ynames = ['='.join([yname, name]) for name in ynames]
File "m:\...\statsmodels\discrete\discrete_model.py", line 3916, in <listcomp>
File "m:\...\statsmodels\discrete\discrete_model.py", line 3520, in summary
yname, yname_list = self._get_endog_name(yname, yname_list)
File "m:\...\statsmodels\discrete\discrete_model.py", line 3916, in _get_endog_name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MultinomialResults has two methods to construct the multivariate specific ynames _get_endog_name uses the endog level names to construct yname_list _maybe_convert_ynames_int converts ints or integer valued floats to string, but leaves other 'levels' unchanged.
If the levels are then not strings, then the string join raises an exception, as in the exampl TypeError: sequence item 1: expected str instance, numpy.float64 found
possible solution use str or repr for anything else in the string concatenation, i.e. extend _maybe_convert_ynames_int
aside _ynames_map seems to be just an alias, not other use found in search in module self._ynames_map = ynames
(not tried yet)
I guess that we can handle the special case when the user provided endog is already 2-d, and then assume that in that case the values are floats in a simplex or in {0, 1} multinomial.
possible problem: patsy also does some conversion, so we might not see the original user provided endog. (Related open issues ...?? where patsy does something different than our code.)
I haven't checked the details in how this works in current code.
@jbrockmendel Do you know a case where pandas series name is anything else than string or None?
AFAIR, we didn't not get failing examples for series name, but maybe the problems with some names and name concatenation in ARIMA is similar.
I'm not aware of any in the existing test cases, but pandas will allow anything hashable as a Series.name. Not a big deal (and definitely shouldn't be allowed to distract from the OP topic).
Activity
josef-pkt commentedon Oct 2, 2017
The specific code
MultinomialResultshas two methods to construct the multivariate specific ynames_get_endog_nameuses the endog level names to constructyname_list_maybe_convert_ynames_intconverts ints or integer valued floats to string, but leaves other 'levels' unchanged.If the levels are then not strings, then the string join raises an exception, as in the exampl
TypeError: sequence item 1: expected str instance, numpy.float64 foundpossible solution use
strorreprfor anything else in the string concatenation, i.e. extend_maybe_convert_ynames_intaside
_ynames_mapseems to be just an alias, not other use found in search in moduleself._ynames_map = ynamesjosef-pkt commentedon Oct 2, 2017
QMLE with 2d endog float in simplex:
(not tried yet)
I guess that we can handle the special case when the user provided endog is already 2-d, and then assume that in that case the values are floats in a simplex or in {0, 1} multinomial.
possible problem: patsy also does some conversion, so we might not see the original user provided endog. (Related open issues ...?? where patsy does something different than our code.)
I haven't checked the details in how this works in current code.
josef-pkt commentedon Oct 7, 2017
suggested quickfix for 0.9: add the
strconversion for anything elsejbrockmendel commentedon Oct 7, 2017
Tangentially related: https://github.com/statsmodels/statsmodels/blob/master/statsmodels/base/data.py#L371 will be incorrect if
arr.nameis Falsy but not None.josef-pkt commentedon Oct 7, 2017
@jbrockmendel Do you know a case where pandas series name is anything else than string or None?
AFAIR, we didn't not get failing examples for series
name, but maybe the problems with some names and name concatenation in ARIMA is similar.jbrockmendel commentedon Oct 7, 2017
I'm not aware of any in the existing test cases, but pandas will allow anything hashable as a
Series.name. Not a big deal (and definitely shouldn't be allowed to distract from the OP topic).josef-pkt commentedon Oct 7, 2017
a reminder about not forgetting py 2 - 3 changes
statsmodels.compat.asstr2 ? (asstr doesn't work for float)
josef-pkt commentedon Oct 7, 2017
more test cases:
pds = pd.Series(np.arange(5), name=0)...
BUG: Fix MNLogit summary with float values
BUG: Fix MNLogit summary with float values