When passing DataFrame, dmatrices returns design matrix with zero rows using standardize in formula
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 990
- Forks
- 106
- Avg merge
- 7d 34m
- Merged PRs (30d)
- 1
Description
When passing a pandas.DataFrame, dmatrices is returning a design matrix with no rows in at least two cases I could find.
Here's some minimal examples.
Case 1: All column values are the same
import pandas as pd
from patsy import dmatrices
df = pd.DataFrame({'a': [1, 1, 1], 'b': [0, 1, 0]})
formula = 'b ~ standardize(a)'
dmatrices(formula, data=df)
give
DesignMatrix with shape (0, 2)
Intercept standardize(a)
Terms:
'Intercept' (column 0)
'standardize(a)' (column 1)
Case 2. Column values are different but contain np.nan
import pandas as pd
import numpy as np
from patsy import dmatrices
df = pd.DataFrame({'a': [2, 3, np.nan], 'b': [0, 1, 0]})
formula = 'b ~ standardize(a)'
dmatrices(formula, data=df)
gives the same
DesignMatrix with shape (0, 2)
Intercept standardize(a)
Terms:
'Intercept' (column 0)
'standardize(a)' (column 1)
patsy version is the latest on conda, 0.5.1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce both cases from the issue using pandas, numpy, and patsy.dmatrices with standardize(a). Start at the dmatrices and standardize entry points and trace how constant values and NaN values affect row handling. Done means the examples no longer produce a design matrix with zero rows, with behavior covered for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100