-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Complex Dtype Support for Hashmap Algos #36482
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
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
1c6b786
Merge master
alimcmaster1 42a46d7
Fix test failures ignore FutureWarning
alimcmaster1 8331d06
Filter warning correctly
alimcmaster1 3ba4169
Fix imports
alimcmaster1 8302589
Merge remote-tracking branch 'remotes/upstream/master' into lucaiones…
alimcmaster1 5068771
Add warning annotation
alimcmaster1 8d65aa7
Remove unrequired annotation
alimcmaster1 8b7ac7d
Merge remote-tracking branch 'remotes/upstream/master' into lucaiones…
alimcmaster1 45c8237
Merge remote-tracking branch 'upstream/master' into lucaionescu-mcmali
alimcmaster1 cb74fe3
Update docs
alimcmaster1 b29404e
Create deepsource.toml
alimcmaster1 f983f4f
Commit Complex handling
alimcmaster1 c2e4e82
run black
alimcmaster1 7c42495
Use pandas.testing
alimcmaster1 41b1faf
Use pandas.testing
alimcmaster1 da53f38
Clean ups
alimcmaster1 32262e7
Merge remote-tracking branch 'upstream/master' into mcmali-complex
alimcmaster1 f4932d9
Move test to sep files
alimcmaster1 328e242
Refactor Tests
alimcmaster1 8d5d517
Merge remote-tracking branch 'upstream/master' into mcmali-complex
alimcmaster1 38e0dc7
Merge remote-tracking branch 'origin/master' into mcmali-complex
alimcmaster1 2008239
Merge master
alimcmaster1 574be58
Complex 128 support
alimcmaster1 e0c3e44
Remove deepsource.toml
alimcmaster1 1b487b8
run black
alimcmaster1 b393a08
Fix tests
alimcmaster1 554090f
Merge remote-tracking branch 'upstream/master' into mcmali-complex
alimcmaster1 ab38ad9
Add ReadMe
alimcmaster1 a28c495
Add ReadMe
alimcmaster1 7a9f960
Merge Master
alimcmaster1 9e558ce
Merge remote-tracking branch 'upstream/master' into mcmali-complex
alimcmaster1 1d11a90
Add np complex64 and np.nan tests
alimcmaster1 737ea96
complex 64 and 128 testing
alimcmaster1 ae7674b
complex 64 and 128 testing
alimcmaster1 d1e00b7
Pep8
alimcmaster1 df28514
isort
alimcmaster1 6b4c10e
More tests
alimcmaster1 9afed5f
Add type info
alimcmaster1 96d5a58
Merge Master
alimcmaster1 e9a4ca2
Fix whatsnew
alimcmaster1 e882b4e
Merge remote-tracking branch 'upstream/master' into mcmali-complex
alimcmaster1 6bf72a0
Updates as per comments
alimcmaster1 e53417d
Fix tests
alimcmaster1 fdf45b1
Merge Master
alimcmaster1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any better locations for this test file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you split the tests to the appropriate files: pandas/tests/series/methods/test_value_counts.py for example |
||
import pytest | ||
|
||
import pandas as pd | ||
from pandas import DataFrame, Index, Series | ||
import pandas.testing as tm | ||
|
||
|
||
class TestBasicComplexSupport: | ||
@pytest.mark.parametrize( | ||
"array,expected", | ||
[ | ||
( | ||
[1 + 1j, 0, 1, 1j, 1 + 2j], | ||
Series([1, 1, 1, 1, 1], index=[1 + 2j, 1 + 1j, 1j, 1, 0]), | ||
), | ||
( | ||
[1 + 2j, 0, 1j, 1, 1j, 1 + 1j], | ||
# index is sorted by value counts in descending order by default | ||
Series([2, 1, 1, 1, 1], index=[1j, 1 + 2j, 1 + 1j, 1, 0]), | ||
), | ||
], | ||
) | ||
def test_value_counts(self, array, expected): | ||
result = pd.value_counts(array) | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"array,expected", | ||
[ | ||
( | ||
[1 + 1j, 0, 1, 1j, 1 + 2j, 1 + 2j], | ||
np.array([(1 + 1j), 0j, (1 + 0j), 1j, (1 + 2j)]), | ||
) | ||
], | ||
) | ||
def test_unique(self, array, expected): | ||
result = pd.unique(array) | ||
np.testing.assert_array_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"array,expected", | ||
[ | ||
( | ||
[0, 1j, 1j, 1, 1 + 1j, 1 + 2j, 1 + 1j], | ||
Series([False, False, True, False, False, False, True], dtype=bool), | ||
) | ||
], | ||
) | ||
def test_duplicated(self, array, expected): | ||
result = Series(array, dtype=np.complex64).duplicated() | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"array,expected", | ||
[ | ||
( | ||
[0, 1j, 1j, 1, 1 + 1j, 1 + 2j, 1 + 1j], | ||
Series([False, True, True, False, True, True, True], dtype=bool), | ||
) | ||
], | ||
) | ||
def test_isin(self, array, expected): | ||
result = Series(array).isin([1j, 1 + 1j, 1 + 2j]) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_factorize(self): | ||
array = [1, 2, 2 + 1j] | ||
labels, uniques = pd.factorize(array) | ||
|
||
expected_labels = np.array([0, 1, 2], dtype=np.intp) | ||
np.testing.assert_array_equal(labels, expected_labels) | ||
|
||
expected_uniques = np.array([(1 + 0j), (2 + 0j), (2 + 1j)], dtype=np.complex64) | ||
np.testing.assert_array_equal(uniques, expected_uniques) | ||
|
||
@pytest.mark.parametrize( | ||
"frame,expected", | ||
[ | ||
( | ||
DataFrame([{"a": 1, "b": 1 + 1j}, {"a": 1, "b": 1 + 2j}]), | ||
DataFrame( | ||
np.array([1, 1], dtype=np.int64), | ||
index=Index([(1 + 1j), (1 + 2j)], dtype="object", name="b"), | ||
columns=Index(["a"], dtype="object"), | ||
), | ||
) | ||
], | ||
) | ||
def test_groupby(self, frame, expected): | ||
result = frame.groupby("b", sort=False).count() | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# sorting of the index should fail since complex numbers are unordered | ||
with pytest.raises( | ||
TypeError, | ||
match="'<' not supported between instances of 'complex' and 'complex'", | ||
): | ||
frame.groupby("b", sort=True).count() | ||
|
||
@pytest.mark.parametrize( | ||
"array,expected", | ||
[ | ||
([0, 1j, 1, 1, 1 + 1j, 1 + 2j], Series([1], dtype=np.complex128)), | ||
([1 + 1j, 2j, 1 + 1j], Series([1 + 1j], dtype=np.complex128)), | ||
], | ||
) | ||
def test_unimode(self, array, expected): | ||
result = Series(array).mode() | ||
tm.assert_series_equal(result, expected) | ||
|
||
# mode tries to sort multimodal series. | ||
# A warning will be raised since complex numbers | ||
# are not ordered. | ||
@pytest.mark.parametrize( | ||
"array,expected", | ||
[ | ||
( | ||
# no modes | ||
[0, 1j, 1, 1 + 1j, 1 + 2j], | ||
Series([0, 1, 1j, 1 + 1j, 1 + 2j], dtype=np.complex128), | ||
), | ||
([1 + 1j, 2j, 1 + 1j, 2j, 3], Series([1 + 1j, 2j], dtype=np.complex128)), | ||
], | ||
) | ||
def test_multimode(self, array, expected): | ||
with pytest.warns(UserWarning): | ||
result = Series(array).mode() | ||
tm.assert_series_equal(result, expected) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.