pydata / pydata/patsy

`build._eval_factor` error condition attempts to access attribute `dtype` on `DataFrame` object, but no such attribute exists

Open
#232 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
990
Forks
106
Avg merge
7d 34m
Merged PRs (30d)
1

Description

In _eval_factor we have:

    # Returns either a 2d ndarray, or a DataFrame, plus is_NA mask
    if factor_info.type == "numerical":
        result = atleast_2d_column_default(result, preserve_pandas=True)

followed by

        if not safe_issubdtype(np.asarray(result).dtype, np.number):
            raise PatsyError(
                "when evaluating numeric factor %s, "
                "I got non-numeric data of type '%s'" % (factor.name(), result.dtype),
                factor,
            )

When result is a pandas.DataFrame but the factor is not actually a safe numeric type, this code will try to raise an error, but in doing so it attempts to access result.dtype which does not exist.

This is not a critical bug; it just results in some pretty confusing error messages.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at build._eval_factor and reproduce the numeric-factor error with a pandas DataFrame containing non-numeric data. Trace the existing error path and verify that it reports the returned data type without raising a secondary attribute error; run the relevant test suite to confirm the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.