Skip to content

FIX: check label dtypes #248

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 1 commit 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
4 changes: 3 additions & 1 deletion pyglmnet/pyglmnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from scipy.special import expit
from scipy.stats import norm
from .utils import logger, set_log_level
from .utils import logger, set_log_level, _check_type
from .base import BaseEstimator, is_classifier, check_version


Expand Down Expand Up @@ -603,6 +603,8 @@ def fit(self, X, y):
self : instance of GLM
The fitted model.
"""
_check_type(self.distr, ['boolean', 'probit'], np.bool, y)
_check_type(self.distr, ['poisson'], np.int, y)
np.random.RandomState(self.random_state)

# checks for group
Expand Down
7 changes: 7 additions & 0 deletions pyglmnet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def tikhonov_from_prior(prior_cov, n_samples, threshold=0.0001):
return Tau


def _check_type(this_distr, distr, allowed_type, y):
if this_distr in distr:
if not isinstance(y, allowed_type):
raise ValueError('Expected y to be of type %s. Got %s'
% (allowed_type, type(y)))


def set_log_level(verbose):
"""Convenience function for setting the log level.

Expand Down