Skip to content
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

REGR: Fix construction of PeriodIndex from strings #33304

Merged
merged 10 commits into from
Apr 10, 2020
Merged

REGR: Fix construction of PeriodIndex from strings #33304

merged 10 commits into from
Apr 10, 2020

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Apr 5, 2020

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dsaxton for the PR


@pytest.mark.parametrize("klass", [list, tuple, np.array, pd.Series])
def test_period_index_construction_from_strings(klass):
result = PeriodIndex(klass(["2020Q1", "2020Q2", "2020Q3", "2020Q4"]), freq="Q")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you do data = ...

so that result = statement is the bit being tested. (i.e. we are not testing the klass constructor)

can you also use the data from the OP, since that was not monotonic



@pytest.mark.parametrize("klass", [list, tuple, np.array, pd.Series])
def test_period_index_construction_from_strings(klass):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the issue number.

@simonjayhawkins simonjayhawkins added Constructors Series/DataFrame/Index/pd.array Constructors Period Period data type labels Apr 6, 2020
@@ -868,3 +868,10 @@ def test_searchsorted_datetimelike_with_listlike_invalid_dtype(values, arg):
msg = "[Unexpected type|Cannot compare]"
with pytest.raises(TypeError, match=msg):
values.searchsorted(arg)


@pytest.mark.parametrize("klass", [list, tuple, np.array, pd.Series])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could maybe add these cases to test_period_array_ok instead/as well.

@dsaxton
Copy link
Member Author

dsaxton commented Apr 6, 2020

Thanks for the feedback @simonjayhawkins . Do you know by chance what's happening in the CI? The error is cryptic and seems unrelated: https://dev.azure.com/pandas-dev/e01c9671-576d-40f3-a1a1-7bef78604087/_apis/build/builds/32518/logs/72

@jorisvandenbossche jorisvandenbossche added this to the 1.1 milestone Apr 10, 2020
@jorisvandenbossche
Copy link
Member

The failurs actually seem related to me. Eg on one of the builds (https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=32640&view=logs&jobId=a67b4c4c-cd2e-5e3c-a361-de73ac9c05f9&j=a67b4c4c-cd2e-5e3c-a361-de73ac9c05f9&t=33d2fdd0-c376-5f94-e6d3-957bdd23a3b8) I see

==================================== ERRORS ==================================== ERRORS ====================================
______________ ERROR collecting pandas/tests/indexes/test_base.py ______________
pandas/tests/indexes/test_base.py:46: in <module>
    class TestIndex(Base):
        tm.assert_index_equal(PeriodIndex(idx.values), idx)
        tm.assert_index_equal(PeriodIndex(list(idx.values)), idx)
    
        msg = "freq not specified and cannot be inferred"
        with pytest.raises(ValueError, match=msg):
            PeriodIndex(idx.asi8)
        with pytest.raises(ValueError, match=msg):
            PeriodIndex(list(idx.asi8))
    
        msg = "'Period' object is not iterable"
        with pytest.raises(TypeError, match=msg):
            PeriodIndex(data=Period("2007", freq="A"))
    
>       result = PeriodIndex(iter(idx))

pandas/tests/indexes/period/test_constructors.py:158: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pandas/core/indexes/period.py:215: in __new__
    data = period_array(data=data, freq=freq)
pandas/core/arrays/period.py:855: in period_array
    return PeriodArray._from_sequence(data, dtype=dtype)
pandas/core/arrays/period.py:197: in _from_sequence
    freq = freq or libperiod.extract_freq(periods)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   def extract_freq(ndarray[object] values):
E   ValueError: Buffer has wrong number of dimensions (expected 1, got 0)

pandas/_libs/tslibs/period.pyx:1469: ValueError

which is at least period related.

@jreback jreback merged commit 716689a into pandas-dev:master Apr 10, 2020
@jreback
Copy link
Contributor

jreback commented Apr 10, 2020

thanks @dsaxton

@dsaxton dsaxton deleted the period-idx branch April 10, 2020 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Constructing PeriodIndex with string data
4 participants