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

A way to solve ValueError: Inferred frequency None from passed values does not conform to passed frequency C #371

Open
wukan1986 opened this issue Apr 21, 2020 · 13 comments

Comments

@wukan1986
Copy link

wukan1986 commented Apr 21, 2020

I find a way to solve the ValueError
I resample the date

factor = factor.resample('M').last()
# ValueError: Inferred frequency None from passed values does not conform to passed frequency C
def _validate_frequency(cls, index, freq, **kwargs):
    return None

pd.core.arrays.datetimelike.DatetimeLikeArrayMixin._validate_frequency = _validate_frequency
# <MonthEnd>
factor.index.levels[0].freq
factor_data = alphalens.utils \
    .get_clean_factor_and_forward_returns(factor, prices,
                                          groupby=groupby,
                                          binning_by_group=binning_by_group,
                                          quantiles=quantiles, bins=bins,
                                          periods=periods,
                                          filter_zscore=filter_zscore,
                                          groupby_labels=groupby_labels)
# set freq to C
factor_data.index.levels[0].freq = 'C'
@tfrojd
Copy link

tfrojd commented Apr 21, 2020

Thanks for sharing!

create_returns_tear_sheet() now seems very slow for me though and gives me the following warnings.

/opt/conda/lib/python3.6/site-packages/pandas/core/arrays/datetimes.py:837: PerformanceWarning: Non-vectorized DateOffset being applied to Series or DatetimeIndex PerformanceWarning,

@alexandrnikitin
Copy link

@wukan1986 Is that related to pandas 1.0.0 or something else?

@wukan1986
Copy link
Author

@alexandrnikitin pandas>=0.25

@vista852
Copy link

It works , Thanks a lot!

@tongxinw
Copy link

tongxinw commented Aug 2, 2020

Thanks for sharing! I have another question while using resampling. resample.last() only keeps 1 row for each month, what if I have multiple rows for each month-end and I would like to keep all of them?

@wukan1986
Copy link
Author

Thanks for sharing! I have another question while using resampling. resample.last() only keeps 1 row for each month, what if I have multiple rows for each month-end and I would like to keep all of them?

df.resample().apply(lambda x:x.tail(2))

@tongxinw
Copy link

tongxinw commented Aug 3, 2020

Thanks for sharing! I have another question while using resampling. resample.last() only keeps 1 row for each month, what if I have multiple rows for each month-end and I would like to keep all of them?

df.resample().apply(lambda x:x.tail(2))

Thanks for your reply! In my understanding, tail(2) would keep the bottom two rows of a certain date, right? What if the data I have only contained month-end prices and factors and I would like to keep all of them. Say I have 1000 assets for 2000-01-31 and thousands of assets for other months as well. I don't think resample('M') would work in this way though. Please feel free to correct me.

@wukan1986
Copy link
Author

Thanks for sharing! I have another question while using resampling. resample.last() only keeps 1 row for each month, what if I have multiple rows for each month-end and I would like to keep all of them?

df.resample().apply(lambda x:x.tail(2))

Thanks for your reply! In my understanding, tail(2) would keep the bottom two rows of a certain date, right? What if the data I have only contained month-end prices and factors and I would like to keep all of them. Say I have 1000 assets for 2000-01-31 and thousands of assets for other months as well. I don't think resample('M') would work in this way though. Please feel free to correct me.

series.unstack().resample()

@Karlish-OMG
Copy link

I find a way to solve the ValueError I resample the date

factor = factor.resample('M').last()
# ValueError: Inferred frequency None from passed values does not conform to passed frequency C
def _validate_frequency(cls, index, freq, **kwargs):
    return None

pd.core.arrays.datetimelike.DatetimeLikeArrayMixin._validate_frequency = _validate_frequency
# <MonthEnd>
factor.index.levels[0].freq
factor_data = alphalens.utils \
    .get_clean_factor_and_forward_returns(factor, prices,
                                          groupby=groupby,
                                          binning_by_group=binning_by_group,
                                          quantiles=quantiles, bins=bins,
                                          periods=periods,
                                          filter_zscore=filter_zscore,
                                          groupby_labels=groupby_labels)
# set freq to C
factor_data.index.levels[0].freq = 'C'

@wukan1986
@luca-s
Thanks for sharing. But this method seems only change the freq from 'None' to 'M'. I adopted this method on my minute-frequency Data, like:

factor_df0=factor_df.unstack().resample('T').last()
factor_df=factor_df0.stack()

price_df=price_df.resample('T').last()
price_df.index.freq

but the warning still arise:
Inferred frequency T from passed values does not conform to passed frequency C

@delsonlizelin
Copy link

Thank you. This works for me.

@AronTian2018
Copy link

you can use date list to filter the date date that has freq=none, such as:
date_list = df.date.groupby('date').min()

than filter factors data by (factors data that not throw to alphalens):
factors.query('date in @date_list‘)

than it works using func "get_clean_factor_and_forward_returns()"

@AronTian2018
Copy link

factor_df0=factor_df.unstack().resample('T').last()
factor_df=factor_df0.stack()

price_df=price_df.resample('T').last()
price_df.index.freq

this works

@gamaiun
Copy link

gamaiun commented Apr 7, 2023

I find a way to solve the ValueError I resample the date

factor = factor.resample('M').last()
# ValueError: Inferred frequency None from passed values does not conform to passed frequency C
def _validate_frequency(cls, index, freq, **kwargs):
    return None

pd.core.arrays.datetimelike.DatetimeLikeArrayMixin._validate_frequency = _validate_frequency
# <MonthEnd>
factor.index.levels[0].freq
factor_data = alphalens.utils \
    .get_clean_factor_and_forward_returns(factor, prices,
                                          groupby=groupby,
                                          binning_by_group=binning_by_group,
                                          quantiles=quantiles, bins=bins,
                                          periods=periods,
                                          filter_zscore=filter_zscore,
                                          groupby_labels=groupby_labels)
# set freq to C
factor_data.index.levels[0].freq = 'C'

Works like a charm! Thank you!

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

9 participants