Skip to content

TST: add test for getting array from series #42939

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

Merged
merged 7 commits into from
Sep 13, 2021

Conversation

horaceklai
Copy link
Contributor

@horaceklai horaceklai commented Aug 8, 2021

@jreback jreback added this to the 1.4 milestone Aug 8, 2021
@jreback jreback added Constructors Series/DataFrame/Index/pd.array Constructors Testing pandas testing functions or related to the test suite Upstream issue Issue related to pandas dependency labels Aug 8, 2021
@@ -182,6 +182,13 @@ def test_array_copy():
assert np.shares_memory(a, b._ndarray) is True


def test_array_from_series():
Copy link
Contributor

Choose a reason for hiding this comment

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

can you instead put in pandas/tests/test_constructors.py

and can you assert the results of each of these with tm.assert_numpy_array_equal.

@@ -182,6 +182,13 @@ def test_array_copy():
assert np.shares_memory(a, b._ndarray) is True


def test_array_from_series():
# GH38543
np.array([pd.Series({0: 0})])
Copy link
Member

Choose a reason for hiding this comment

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

Could you use pytest.mark.parameterize to test each case?

Additionally, these tests should follow the format

result = np.array(np.array([pd.Series({0: 0})]))
expected = np.array(...) # another way to construct the result
tm.assert_numpy_array_equal(result, expected)

@horaceklai horaceklai force-pushed the test-series_to_np_array branch from 0b32f59 to 777864d Compare August 11, 2021 20:59
@mroeschke
Copy link
Member

Mind investigating the failures @horaceklai?

@horaceklai
Copy link
Contributor Author

Mind investigating the failures @horaceklai?

Do you mean investigating the bug that the issue initially described?

The failure has to do with the bug reoccurring. I thought it was fixed from the comments written before I took this issue, but it is here now.

@@ -0,0 +1,18 @@
import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry menat pandas/tests/series/test_constructors.py

@horaceklai horaceklai requested a review from jreback August 22, 2021 08:48
@jreback
Copy link
Contributor

jreback commented Aug 31, 2021

can you merge master and ping on green.

Copy link
Member

@lithomas1 lithomas1 left a comment

Choose a reason for hiding this comment

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

You need to skip this test on old numpy. I believe 1.19 is the first version it works on but haven't checked.

@horaceklai
Copy link
Contributor Author

You need to skip this test on old numpy. I believe 1.19 is the first version it works on but haven't checked.

Hi Thomas,

I am not sure how to skip certain tests for old numpy. Mind giving me a tip?

Thanks,
Horace

@lithomas1
Copy link
Member

Have a look at the pytest.mark.skipif decorator(https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-skipif-ref).

You'll also need

np_version_under1p19 = _nlv < Version("1.19")
from pandas.compat.numpy.
This variable is a boolean that tells you if the numpy version is under 1.19

So you'll have something like

from pandas.compat.numpy import np_version_under1p19
...
...
...
@pytest.mark.skipif(np_version_under1p19, reason="fails on numpy below 1.19")
[your test code]

Let me know if you have more questions.

@horaceklai
Copy link
Contributor Author

Have a look at the pytest.mark.skipif decorator(https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-skipif-ref).

You'll also need

np_version_under1p19 = _nlv < Version("1.19")

from pandas.compat.numpy.
This variable is a boolean that tells you if the numpy version is under 1.19
So you'll have something like

from pandas.compat.numpy import np_version_under1p19
...
...
...
@pytest.mark.skipif(np_version_under1p19, reason="fails on numpy below 1.19")
[your test code]

Let me know if you have more questions.

Thanks! You pretty much did all the work for me and I learned something new!

@horaceklai horaceklai requested a review from lithomas1 September 6, 2021 12:34
({1: 1}, np.array([[1]], dtype=np.int64)),
],
)
@pytest.mark.skipif(np_version_under1p19, reason="fails on numpy below 1.19")
Copy link
Contributor

Choose a reason for hiding this comment

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

can you write a tests that specifically tests < numpy 1.19. e.g. an asserts the error that happens (OT I wonder if this is fixable on the pandas side).

@horaceklai
Copy link
Contributor Author

horaceklai commented Sep 6, 2021 via email

@lithomas1
Copy link
Member

@horaceklai Can you fix the test failures?

@horaceklai horaceklai requested a review from jreback September 12, 2021 21:06
@horaceklai
Copy link
Contributor Author

@horaceklai Can you fix the test failures?

I think I fixed it now with the error message not matching, but now I'm having another error that I don't know if it is related. The test is taking too much time (> 1hr)

Copy link
Member

@lithomas1 lithomas1 left a comment

Choose a reason for hiding this comment

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

Lgtm. Thanks for the PR. Don't worry about the timeouts.

@mroeschke mroeschke merged commit a54aa39 into pandas-dev:master Sep 13, 2021
@mroeschke
Copy link
Member

Thanks @horaceklai

AlexeyGy pushed a commit to AlexeyGy/pandas that referenced this pull request Sep 13, 2021
* TST: add test for getting array from series

* TST: add test for getting array from series

* add skipif for low versions of numpy

* add dtype np.int64

* add test to check that exception is raised for np version < 1.19

* change matched string to '0'
AlexeyGy pushed a commit to AlexeyGy/pandas that referenced this pull request Sep 13, 2021
* TST: add test for getting array from series

* TST: add test for getting array from series

* add skipif for low versions of numpy

* add dtype np.int64

* add test to check that exception is raised for np version < 1.19

* change matched string to '0'
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 Testing pandas testing functions or related to the test suite Upstream issue Issue related to pandas dependency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

np.array([pd.Series({'a':'a'})]) works but np.array([pd.Series({1:1})]) doesn't
4 participants