matthewwardrop / formulaic

A high-performance implementation of Wilkinson formulas for Python.
MIT License
340 stars 24 forks source link

`_ordering="none"` is ignored when a dependent variable is included #191

Open eirki opened 1 month ago

eirki commented 1 month ago

Thanks for the very useful library!

I'm having some issues with retaining the order of the terms as they are in the formula. Using the example from the README, but with a c  ~ added, yield the following result:

In [2]: {
   ...:     "degree": Formula("c ~ z + z:a + z:b:a + g").rhs,
   ...:     "none": Formula("c ~ z + z:a + z:b:a + g", _ordering="none").rhs,
   ...:     "sort": Formula("c ~ z + z:a + z:b:a + g", _ordering="sort").rhs,
   ...: }
Out[2]:
{'degree': 1 + z + g + z:a + z:b:a,
 'none': 1 + z + g + z:a + z:b:a,
 'sort': 1 + g + z + a:z + a:b:z}

Notice the 'none' example is identical to the 'degree' (default) option. Is there a reason for this?

matthewwardrop commented 6 days ago

Hmmm... good observation, especially since the behaviour in the docs indicates otherwise. I'll take a look at this shortly... I suspect that _ordering is just not being propagated correctly.