-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Enable many complex number tests #54761
Changes from 34 commits
6125494
e7a285a
02719d9
f9bfeb9
077213f
9fda0ef
d25baa2
ad841bf
7535374
7ef6052
f1139f5
19d3127
67e2dbc
909ced4
48cb330
bc96021
d98e6f0
dabaf6f
61c9b32
6ed24ad
e923878
5efad33
51450c8
c31b213
9473130
a86c896
de56177
198a16d
554a5c3
6ddb7f7
c4a17a7
040c98b
3a58f5a
29aa747
5210c8b
9f4bea5
be1f02b
b3edefa
89ea60b
4dc3bea
4e273fa
abfdedb
59b50c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1003,7 +1003,7 @@ def test_frame_operators_none_to_nan(self): | |
df = pd.DataFrame({"a": ["a", None, "b"]}) | ||
tm.assert_frame_equal(df + df, pd.DataFrame({"a": ["aa", np.nan, "bb"]})) | ||
|
||
@pytest.mark.parametrize("dtype", ("float", "int64")) | ||
@pytest.mark.parametrize("dtype", ("float", "int64", "complex128")) | ||
def test_frame_operators_empty_like(self, dtype): | ||
# Test for issue #10181 | ||
frames = [ | ||
|
@@ -1101,7 +1101,7 @@ def test_series_divmod_zero(self): | |
class TestUFuncCompat: | ||
# TODO: add more dtypes | ||
@pytest.mark.parametrize("holder", [Index, RangeIndex, Series]) | ||
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64]) | ||
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64, np.complex128]) | ||
def test_ufunc_compat(self, holder, dtype): | ||
box = Series if holder is Series else Index | ||
|
||
|
@@ -1116,45 +1116,75 @@ def test_ufunc_compat(self, holder, dtype): | |
tm.assert_equal(result, expected) | ||
|
||
# TODO: add more dtypes | ||
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64]) | ||
@pytest.mark.parametrize("dtype", [np.int64, np.uint64, np.float64, np.complex128]) | ||
def test_ufunc_coercions(self, index_or_series, dtype): | ||
idx = index_or_series([1, 2, 3, 4, 5], dtype=dtype, name="x") | ||
box = index_or_series | ||
|
||
result = np.sqrt(idx) | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp = Index(np.sqrt(np.array([1, 2, 3, 4, 5], dtype=np.float64)), name="x") | ||
if result.dtype.kind == "c": | ||
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. @jbrockmendel is there something in our type conversion / introspection functions that lets us cast to the nearest inexact data type? If not that might be something we want to do here or in a follow up PR to better handle this 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.
I don't think so, no. i expected maybe_promote to do that, but looks like it always gives float64 |
||
assert result.dtype == dtype and isinstance(result, box) | ||
exp_dtype = dtype | ||
else: | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp_dtype = np.float64 | ||
exp = Index(np.sqrt(np.array([1, 2, 3, 4, 5], dtype=exp_dtype)), name="x") | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = np.divide(idx, 2.0) | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp = Index([0.5, 1.0, 1.5, 2.0, 2.5], dtype=np.float64, name="x") | ||
if result.dtype.kind == "c": | ||
assert result.dtype == dtype and isinstance(result, box) | ||
exp_dtype = dtype | ||
else: | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp_dtype = np.float64 | ||
exp = Index([0.5, 1.0, 1.5, 2.0, 2.5], dtype=exp_dtype, name="x") | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
# _evaluate_numeric_binop | ||
result = idx + 2.0 | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp = Index([3.0, 4.0, 5.0, 6.0, 7.0], dtype=np.float64, name="x") | ||
if result.dtype.kind == "c": | ||
assert result.dtype == dtype and isinstance(result, box) | ||
exp_dtype = dtype | ||
else: | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp_dtype = np.float64 | ||
MichaelTiemannOSC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exp = Index([3.0, 4.0, 5.0, 6.0, 7.0], dtype=exp_dtype, name="x") | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = idx - 2.0 | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp = Index([-1.0, 0.0, 1.0, 2.0, 3.0], dtype=np.float64, name="x") | ||
if result.dtype.kind == "c": | ||
assert result.dtype == dtype and isinstance(result, box) | ||
exp_dtype = dtype | ||
else: | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp_dtype = np.float64 | ||
exp = Index([-1.0, 0.0, 1.0, 2.0, 3.0], dtype=exp_dtype, name="x") | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = idx * 1.0 | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp = Index([1.0, 2.0, 3.0, 4.0, 5.0], dtype=np.float64, name="x") | ||
if result.dtype.kind == "c": | ||
assert result.dtype == dtype and isinstance(result, box) | ||
exp_dtype = dtype | ||
else: | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp_dtype = np.float64 | ||
exp = Index([1.0, 2.0, 3.0, 4.0, 5.0], dtype=exp_dtype, name="x") | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
result = idx / 2.0 | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp = Index([0.5, 1.0, 1.5, 2.0, 2.5], dtype=np.float64, name="x") | ||
if result.dtype.kind == "c": | ||
assert result.dtype == dtype and isinstance(result, box) | ||
exp_dtype = dtype | ||
else: | ||
assert result.dtype == "f8" and isinstance(result, box) | ||
exp_dtype = np.float64 | ||
exp = Index([0.5, 1.0, 1.5, 2.0, 2.5], dtype=exp_dtype, name="x") | ||
exp = tm.box_expected(exp, box) | ||
tm.assert_equal(result, exp) | ||
|
||
|
@@ -1408,7 +1438,7 @@ def test_numeric_compat2_floordiv(self, idx, div, expected): | |
# __floordiv__ | ||
tm.assert_index_equal(idx // div, expected, exact=True) | ||
|
||
@pytest.mark.parametrize("dtype", [np.int64, np.float64]) | ||
@pytest.mark.parametrize("dtype", [np.int64, np.float64, np.complex128]) | ||
@pytest.mark.parametrize("delta", [1, 0, -1]) | ||
def test_addsub_arithmetic(self, dtype, delta): | ||
# GH#8142 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,7 +343,8 @@ def test_setitem_slice_array(self, data): | |
|
||
def test_setitem_scalar_key_sequence_raise(self, data): | ||
arr = data[:5].copy() | ||
with tm.external_error_raised(ValueError): | ||
# complex128 data raises TypeError; other numeric types raise ValueError | ||
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. Do you know where the 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. When running
When
The ValueError seems to come from Numpy, and the TypeError seems to come from Python, both coming from 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. Could we catch the Python TypeError and reraise as a ValueError? 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. I've amended the PR to attempt this. Please let me know what you think. |
||
with pytest.raises((ValueError, TypeError)): | ||
arr[0] = arr[[0, 1]] | ||
|
||
def test_setitem_preserves_views(self, data): | ||
|
@@ -439,7 +440,7 @@ def test_setitem_invalid(self, data, invalid_scalar): | |
data[:] = invalid_scalar | ||
|
||
def test_setitem_2d_values(self, data): | ||
# GH50085 | ||
# GH54445 | ||
original = data.copy() | ||
df = pd.DataFrame({"a": data, "b": data}) | ||
df.loc[[0, 1], :] = df.loc[[1, 0], :].values | ||
|
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.
not complex64?
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.
I'd be happy to add complex64 to the test suite, but thought it better to do one case (complex128) at a time. I didn't want to add something (
values.dtype.itemsize == 8
) that wasn't tested by the test suite.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.
not a deal-breaker, but id prefer to do them both in this pass. or at least leave a comment explaining why one is excluded