Skip to content

TST: Test for the Enum triggering TypeError (#22551 issue) #47715

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 20 commits into from
Jul 16, 2022

Conversation

Shadimrad
Copy link
Contributor

@Shadimrad Shadimrad commented Jul 14, 2022

@pep8speaks
Copy link

pep8speaks commented Jul 14, 2022

Hello @Shadimrad! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-07-16 02:19:24 UTC

@Shadimrad Shadimrad changed the title TST Test for the Enum triggering TypeError Jul 14, 2022
@Shadimrad Shadimrad changed the title Test for the Enum triggering TypeError Test for the Enum triggering TypeError (#22551 issue) Jul 14, 2022
@Shadimrad Shadimrad changed the title Test for the Enum triggering TypeError (#22551 issue) TST: Test for the Enum triggering TypeError (#22551 issue) Jul 14, 2022
@@ -20,3 +22,16 @@ def test_get_value(self, float_frame):
result = float_frame._get_value(idx, col)
expected = float_frame[col][idx]
assert result == expected


def test_enum_value():
Copy link
Member

Choose a reason for hiding this comment

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

  1. Could you name this test test_enum_column_equality
  2. Could you move this to pandas/tests/frame/test_arithmetic.py?
  3. Also below could you structure the test like
result = q1[Cols.col1] == q2[Cols.col1]
expected = ...
tm.assert_equal(result, expected)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Thank you for your guide.

Copy link
Contributor Author

@Shadimrad Shadimrad Jul 15, 2022

Choose a reason for hiding this comment

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

@mroeschke by result = q1[Cols.col1] == q2[Cols.col1] do you mean that I remove the .all() method as well?

Copy link
Member

Choose a reason for hiding this comment

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

Correct

Copy link
Member

Choose a reason for hiding this comment

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

The changes in this file can be removed now.

Copy link
Member

@mroeschke mroeschke Jul 15, 2022

Choose a reason for hiding this comment

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

If you inspect result, it's a Series

In [1]:  from enum import Enum

In [2]:     Cols = Enum("Cols", "col1 col2")
   ...:
   ...:     q1 = DataFrame({Cols.col1: [1, 2, 3]})
   ...:     q2 = DataFrame({Cols.col1: [1, 2, 3]})
   ...:
   ...:     result = q1[Cols.col1] == q2[Cols.col1]

In [3]: result
Out[3]:
0    True
1    True
2    True
Name: Cols.col1, dtype: bool

So expected should also be a Series

Copy link
Contributor Author

@Shadimrad Shadimrad Jul 15, 2022

Choose a reason for hiding this comment

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

@mroeschke
Right. but when I created the series and tried to compare,

data = np.array([True, True, True])
expected = pd.Series(data)

checking if expected == result gave me the Error that the truth value of the Series is ambiguous, that is why. Unless tm.assert_equal accounts for that. update: it did not.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, tm.assert_equal will check the values and the aspects of the Series

In [1]:  from enum import Enum

In [2]:     Cols = Enum("Cols", "col1 col2")
   ...:
   ...:     q1 = DataFrame({Cols.col1: [1, 2, 3]})
   ...:     q2 = DataFrame({Cols.col1: [1, 2, 3]})
   ...:
   ...:     result = q1[Cols.col1] == q2[Cols.col1]

In [3]: result
Out[3]:
0    True
1    True
2    True
Name: Cols.col1, dtype: bool

In [4]: import pandas._testing as tm

In [5]: epxected = pd.Series([True, True, True], name=Cols.col1)

In [6]: tm.assert_series_equal(result, epxected)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: changing it to tm.assert_series_equal(result, expected) , hoping it works.

Copy link
Contributor Author

@Shadimrad Shadimrad Jul 15, 2022

Choose a reason for hiding this comment

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

Oh, I've just seen your reply. There was a syntax issue that I fixed. pd.Series now replaced with Series which hopefully should be working now. Thank you for your guidance as well.

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Jul 14, 2022
@Shadimrad Shadimrad marked this pull request as draft July 15, 2022 20:14
@Shadimrad Shadimrad marked this pull request as ready for review July 15, 2022 20:16
@Shadimrad Shadimrad marked this pull request as draft July 15, 2022 20:30
@Shadimrad Shadimrad marked this pull request as ready for review July 16, 2022 00:00
@Shadimrad Shadimrad requested a review from mroeschke July 16, 2022 03:59
@Shadimrad
Copy link
Contributor Author

I believe it's done! @mroeschke

@mroeschke mroeschke merged commit e3698dd into pandas-dev:main Jul 16, 2022
@mroeschke
Copy link
Member

Thanks, great job @Shadimrad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

columns comparison with Enum column name triggers TypeError
3 participants