Skip to content

CI: ValueError: Must pass 2-d input in constructor #34239

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
charlesdong1991 opened this issue May 18, 2020 · 0 comments
Closed

CI: ValueError: Must pass 2-d input in constructor #34239

charlesdong1991 opened this issue May 18, 2020 · 0 comments
Labels
CI Continuous Integration

Comments

@charlesdong1991
Copy link
Member

seems df construction fail at some special cases, have seen the errors in multiple PRs

@pytest.mark.xfail(_is_numpy_dev, reason="Interprets list of frame as 3D")
    def test_constructor_list_frames(self):
        # see gh-3243
>       result = DataFrame([DataFrame()])

pandas/tests/frame/test_constructors.py:153: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pandas/core/frame.py:514: in __init__
    mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy)
pandas/core/internals/construction.py:190: in init_ndarray
    values = _prep_ndarray(values, copy=copy)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

values = array([], shape=(1, 0, 0), dtype=float64), copy = False

    def _prep_ndarray(values, copy: bool = True) -> np.ndarray:
        if not isinstance(values, (np.ndarray, ABCSeries, Index)):
            if len(values) == 0:
                return np.empty((0, 0), dtype=object)
            elif isinstance(values, range):
                arr = np.arange(values.start, values.stop, values.step, dtype="int64")
                return arr[..., np.newaxis]
    
            def convert(v):
                return maybe_convert_platform(v)
    
            # we could have a 1-dim or 2-dim list here
            # this is equiv of np.asarray, but does object conversion
            # and platform dtype preservation
            try:
                if is_list_like(values[0]) or hasattr(values[0], "len"):
                    values = np.array([convert(v) for v in values])
                elif isinstance(values[0], np.ndarray) and values[0].ndim == 0:
                    # GH#21861
                    values = np.array([convert(v) for v in values])
                else:
                    values = convert(values)
            except (ValueError, TypeError):
                values = convert(values)
    
        else:
    
            # drop subclass info, do not copy data
            values = np.asarray(values)
            if copy:
                values = values.copy()
    
        if values.ndim == 1:
            values = values.reshape((values.shape[0], 1))
        elif values.ndim != 2:
>           raise ValueError("Must pass 2-d input")
E           ValueError: Must pass 2-d input
@charlesdong1991 charlesdong1991 added Needs Triage Issue that has not been reviewed by a pandas team member Usage Question CI Continuous Integration and removed Needs Triage Issue that has not been reviewed by a pandas team member Usage Question labels May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration
Projects
None yet
Development

No branches or pull requests

1 participant