Skip to content

Commit

Permalink
fix bug with pandas categorical series (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomicapretto authored Apr 13, 2022
1 parent 09aeb5b commit e6c1b84
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

### Deprecation

### v0.3.2

### Maintenance and fixes

- Fixed a bug in `CategoricalBox` because it failed to convert categorical series to numpy arrays. Now it works. (#72)

### v0.3.1

### Maintenance and fixes
Expand Down
2 changes: 1 addition & 1 deletion formulae/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def data(self):
@data.setter
def data(self, value):
if isinstance(value, pd.Series):
value = value.values
value = np.asarray(value)
if not (isinstance(value, np.ndarray) and value.ndim == 1): # pragma: no cover
raise ValueError("The data argument must be one dimensional array-like")
self._data = value
Expand Down
6 changes: 6 additions & 0 deletions formulae/tests/test_design_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,3 +1131,9 @@ def test_extra_namespace(data):
)
df = dm.common.as_dataframe()
assert df["myfunc(x3)"].equals(np.log(df["x3"]))


def test_categorical_series():
data = pd.DataFrame({"x": list("abc") * 10})
data["x"] = pd.Categorical(data["x"], list("abc"), ordered=True)
design_matrices("S(x)", data)
2 changes: 1 addition & 1 deletion formulae/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.1"
__version__ = "0.3.2"

0 comments on commit e6c1b84

Please sign in to comment.