Skip to content

CLN: fix flake8 warnings in pandas/stats #12114

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/stats/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# pylint: disable-msg=W0611,W0614,W0401

# flake8: noqa

from pandas.stats.moments import *
from pandas.stats.interface import ols
from pandas.stats.fama_macbeth import fama_macbeth
8 changes: 6 additions & 2 deletions pandas/stats/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
2: 'expanding'
}
# also allow 'rolling' as key
_WINDOW_TYPES.update((v, v) for k,v in list(_WINDOW_TYPES.items()))
_WINDOW_TYPES.update((v, v) for k, v in list(_WINDOW_TYPES.items()))
_ADDITIONAL_CLUSTER_TYPES = set(("entity", "time"))


def _get_cluster_type(cluster_type):
# this was previous behavior
if cluster_type is None:
Expand All @@ -20,15 +21,18 @@ def _get_cluster_type(cluster_type):
return final_type
raise ValueError('Unrecognized cluster type: %s' % cluster_type)


def _get_window_type(window_type):
# e.g., 0, 1, 2
final_type = _WINDOW_TYPES.get(window_type)
# e.g., 'full_sample'
final_type = final_type or _WINDOW_TYPES.get(str(window_type).lower().replace(" ", "_"))
final_type = final_type or _WINDOW_TYPES.get(
str(window_type).lower().replace(" ", "_"))
if final_type is None:
raise ValueError('Unrecognized window type: %s' % window_type)
return final_type


def banner(text, width=80):
"""

Expand Down
9 changes: 6 additions & 3 deletions pandas/stats/fama_macbeth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pandas.stats.common as common
from pandas.util.decorators import cache_readonly

# flake8: noqa

def fama_macbeth(**kwargs):
"""Runs Fama-MacBeth regression.
Expand All @@ -28,6 +29,7 @@ def fama_macbeth(**kwargs):


class FamaMacBeth(StringMixin):

def __init__(self, y, x, intercept=True, nw_lags=None,
nw_lags_beta=None,
entity_effects=False, time_effects=False, x_effects=None,
Expand All @@ -39,7 +41,7 @@ def __init__(self, y, x, intercept=True, nw_lags=None,
FutureWarning, stacklevel=4)

if dropped_dummies is None:
dropped_dummies = {}
dropped_dummies = {}
self._nw_lags_beta = nw_lags_beta

from pandas.stats.plm import MovingPanelOLS
Expand Down Expand Up @@ -99,7 +101,7 @@ def _results(self):
def _coef_table(self):
buffer = StringIO()
buffer.write('%13s %13s %13s %13s %13s %13s\n' %
('Variable', 'Beta', 'Std Err', 't-stat', 'CI 2.5%', 'CI 97.5%'))
('Variable', 'Beta', 'Std Err', 't-stat', 'CI 2.5%', 'CI 97.5%'))
template = '%13s %13.4f %13.4f %13.2f %13.4f %13.4f\n'

for i, name in enumerate(self._cols):
Expand Down Expand Up @@ -148,12 +150,13 @@ def summary(self):


class MovingFamaMacBeth(FamaMacBeth):

def __init__(self, y, x, window_type='rolling', window=10,
intercept=True, nw_lags=None, nw_lags_beta=None,
entity_effects=False, time_effects=False, x_effects=None,
cluster=None, dropped_dummies=None, verbose=False):
if dropped_dummies is None:
dropped_dummies = {}
dropped_dummies = {}
self._window_type = common._get_window_type(window_type)
self._window = window

Expand Down
6 changes: 3 additions & 3 deletions pandas/stats/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def ols(**kwargs):
result = ols(y=y, x=x)

# Run expanding panel OLS with window 10 and entity clustering.
result = ols(y=y, x=x, cluster='entity', window_type='expanding', window=10)
result = ols(y=y, x=x, cluster='entity', window_type='expanding',
window=10)

Returns
-------
Expand All @@ -85,12 +86,11 @@ def ols(**kwargs):
"""

if (kwargs.get('cluster') is not None and
kwargs.get('nw_lags') is not None):
kwargs.get('nw_lags') is not None):
raise ValueError(
'Pandas OLS does not work with Newey-West correction '
'and clustering.')


pool = kwargs.get('pool')
if 'pool' in kwargs:
del kwargs['pool']
Expand Down
7 changes: 5 additions & 2 deletions pandas/stats/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from pandas import compat
import numpy as np

from pandas.core.api import Series, DataFrame, isnull, notnull
from pandas.core.api import Series, DataFrame
from pandas.core.series import remove_na
from pandas.compat import zip
from pandas.compat import zip, lrange
import pandas.core.common as com


def zscore(series):
Expand Down Expand Up @@ -42,6 +43,7 @@ def correl_ts(frame1, frame2):
def correl_xs(frame1, frame2):
return correl_ts(frame1.T, frame2.T)


def percentileofscore(a, score, kind='rank'):
"""The percentile rank of a score relative to a list of scores.

Expand Down Expand Up @@ -131,6 +133,7 @@ def percentileofscore(a, score, kind='rank'):
else:
raise ValueError("kind can only be 'rank', 'strict', 'weak' or 'mean'")


def percentileRank(frame, column=None, kind='mean'):
"""
Return score at percentile for each point in time (cross-section)
Expand Down
Loading