-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
TST: add test for getting array from series #42939
Conversation
pandas/tests/arrays/test_array.py
Outdated
@@ -182,6 +182,13 @@ def test_array_copy(): | |||
assert np.shares_memory(a, b._ndarray) is True | |||
|
|||
|
|||
def test_array_from_series(): |
There was a problem hiding this comment.
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
.
pandas/tests/arrays/test_array.py
Outdated
@@ -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})]) |
There was a problem hiding this comment.
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)
3a606ad
to
0b32f59
Compare
0b32f59
to
777864d
Compare
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. |
pandas/tests/test_constructors.py
Outdated
@@ -0,0 +1,18 @@ | |||
import numpy as np |
There was a problem hiding this comment.
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
can you merge master and ping on green. |
There was a problem hiding this 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.
Hi Thomas, I am not sure how to skip certain tests for old numpy. Mind giving me a tip? Thanks, |
Have a look at the You'll also need pandas/pandas/compat/numpy/__init__.py Line 12 in 35d52ff
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
Let me know if you have more questions. |
Thanks! You pretty much did all the work for me and I learned something new! |
({1: 1}, np.array([[1]], dtype=np.int64)), | ||
], | ||
) | ||
@pytest.mark.skipif(np_version_under1p19, reason="fails on numpy below 1.19") |
There was a problem hiding this comment.
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).
Yes, good idea.
…On Mon, Sep 6, 2021, 5:25 PM Jeff Reback ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pandas/tests/series/test_constructors.py
<#42939 (comment)>:
> @@ -1840,3 +1841,17 @@ def test_constructor(rand_series_with_duplicate_datetimeindex):
dups = rand_series_with_duplicate_datetimeindex
assert isinstance(dups, Series)
assert isinstance(dups.index, DatetimeIndex)
+
+
***@***.***(
+ "input_dict,expected",
+ [
+ ({0: 0}, np.array([[0]], dtype=np.int64)),
+ ({"a": "a"}, np.array([["a"]], dtype=object)),
+ ({1: 1}, np.array([[1]], dtype=np.int64)),
+ ],
+)
***@***.***(np_version_under1p19, reason="fails on numpy below 1.19")
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).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#42939 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKTQNIYUAY6N3G6P42VDOQTUATMQHANCNFSM5BY3FVMA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@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) |
There was a problem hiding this 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.
Thanks @horaceklai |
* 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'
* 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'
np.array([pd.Series({'a':'a'})])
works butnp.array([pd.Series({1:1})])
doesn't #38543