Skip to content

Move _feols_input_checks functions from feols.py to dev_utils.py #873

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dist
.mypy_cache
.pytest_cache
.vscode
.coverage
.coverage*
*.pyc
__pycache__/
#docs/figures
Expand Down
32 changes: 0 additions & 32 deletions pyfixest/estimation/feols_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2506,38 +2506,6 @@ def update(
return beta_n_plus_1


def _feols_input_checks(Y: np.ndarray, X: np.ndarray, weights: np.ndarray):
"""
Perform basic checks on the input matrices Y and X for the FEOLS.

Parameters
----------
Y : np.ndarray
FEOLS input matrix Y.
X : np.ndarray
FEOLS input matrix X.
weights : np.ndarray
FEOLS weights.

Returns
-------
None
"""
if not isinstance(Y, (np.ndarray)):
raise TypeError("Y must be a numpy array.")
if not isinstance(X, (np.ndarray)):
raise TypeError("X must be a numpy array.")
if not isinstance(weights, (np.ndarray)):
raise TypeError("weights must be a numpy array.")

if Y.ndim != 2:
raise ValueError("Y must be a 2D array")
if X.ndim != 2:
raise ValueError("X must be a 2D array")
if weights.ndim != 2:
raise ValueError("weights must be a 2D array")


def _get_vcov_type(vcov: str, fval: str):
"""
Get variance-covariance matrix type.
Expand Down
3 changes: 1 addition & 2 deletions pyfixest/estimation/fepois_.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,14 @@ def prepare_model_matrix(self):
self._fe.drop(na_separation, axis=0, inplace=True)
self._data.drop(na_separation, axis=0, inplace=True)
self._N = self._Y.shape[0]
self._N_rows = self._N # ok as weights not supported
self._N_rows = self._N # ok as weights not supported

self.na_index = np.concatenate([self.na_index, np.array(na_separation)])
self.n_separation_na = len(na_separation)
# possible to have dropped fixed effects level due to separation
self._k_fe = self._fe.nunique(axis=0) if self._has_fixef else None
self._n_fe = np.sum(self._k_fe > 1) if self._has_fixef else 0


def to_array(self):
"Turn estimation DataFrames to np arrays."
self._Y, self._X, self._Z = (
Expand Down
2 changes: 1 addition & 1 deletion pyfixest/estimation/vcov_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _count_G_for_ssc_correction(

return G


def _get_vcov_type(
vcov: Union[str, dict[str, str], None], fval: str
) -> Union[str, dict[str, str]]:
Expand Down Expand Up @@ -96,7 +97,6 @@ def _get_vcov_type(
return vcov_type # type: ignore



def _prepare_twoway_clustering(clustervar: list, cluster_df: pd.DataFrame):
cluster_one = clustervar[0]
cluster_two = clustervar[1]
Expand Down
32 changes: 32 additions & 0 deletions pyfixest/utils/dev_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,35 @@
level = match.group(2)

return f"C({variable})", level


def _feols_input_checks(Y: np.ndarray, X: np.ndarray, weights: np.ndarray):
"""
Perform basic checks on the input matrices Y and X for the FEOLS.

Parameters
----------
Y : np.ndarray
FEOLS input matrix Y.
X : np.ndarray
FEOLS input matrix X.
weights : np.ndarray
FEOLS weights.

Returns
-------
None
"""
if not isinstance(Y, (np.ndarray)):
raise TypeError("Y must be a numpy array.")
if not isinstance(X, (np.ndarray)):
raise TypeError("X must be a numpy array.")
if not isinstance(weights, (np.ndarray)):
raise TypeError("weights must be a numpy array.")

Check warning on line 218 in pyfixest/utils/dev_utils.py

View check run for this annotation

Codecov / codecov/patch

pyfixest/utils/dev_utils.py#L213-L218

Added lines #L213 - L218 were not covered by tests

if Y.ndim != 2:
raise ValueError("Y must be a 2D array")
if X.ndim != 2:
raise ValueError("X must be a 2D array")
if weights.ndim != 2:
raise ValueError("weights must be a 2D array")

Check warning on line 225 in pyfixest/utils/dev_utils.py

View check run for this annotation

Codecov / codecov/patch

pyfixest/utils/dev_utils.py#L220-L225

Added lines #L220 - L225 were not covered by tests
Binary file removed tests/.coverage
Binary file not shown.
Loading