Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patsy loses DatetimeIndex freq information even if no NA values #125

Open
ChadFulton opened this issue Jun 1, 2018 · 0 comments
Open

Patsy loses DatetimeIndex freq information even if no NA values #125

ChadFulton opened this issue Jun 1, 2018 · 0 comments

Comments

@ChadFulton
Copy link

(This is probably better described as a pandas bug, see pandas-dev/pandas#21282, but maybe patsy wants to patch this too?)

Reproducible example:

(proceeding from the above code)

import pandas as pd
import patsy

index = pd.DatetimeIndex(start='1990', end='1994', freq='AS')
data = pd.Series([0, 1, 2, 3, 4], name='y', index=index)
print(data.index)

lhs, rhs = patsy.dmatrices('y ~ 1', data={'y':data}, return_type='dataframe')
print(lhs.index)

The first print statement yields:

DatetimeIndex(['1990-01-01', '1991-01-01', '1992-01-01', '1993-01-01',
               '1994-01-01'],
              dtype='datetime64[ns]', freq='AS-JAN')

Whereas the second yields:

DatetimeIndex(['1990-01-01', '1991-01-01', '1992-01-01', '1993-01-01',
               '1994-01-01'],
              dtype='datetime64[ns]', freq=None)

This is a consequence of pandas-dev/pandas#21282 as it affects the following function in patsy/missing.py:

def _handle_NA_drop(self, values, is_NAs, origins):
        total_mask = np.zeros(is_NAs[0].shape[0], dtype=bool)
        for is_NA in is_NAs:
            total_mask |= is_NA
        good_mask = ~total_mask
        # "..." to handle 1- versus 2-dim indexing
        return [v[good_mask, ...] for v in values]

when v is the DatetimeIndex, the ellipses cause the index to lose frequency information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant