-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
[ArrayManager] TST: arithmetic test #39753
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
Changes from all commits
4489214
f6671a4
f30d917
cd40b96
8fa1e59
a526544
fbffcad
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 |
---|---|---|
|
@@ -1748,7 +1748,9 @@ def test_tdarr_div_length_mismatch(self, box_with_array): | |
# ------------------------------------------------------------------ | ||
# __floordiv__, __rfloordiv__ | ||
|
||
def test_td64arr_floordiv_td64arr_with_nat(self, box_with_array): | ||
def test_td64arr_floordiv_td64arr_with_nat( | ||
self, box_with_array, using_array_manager | ||
): | ||
# GH#35529 | ||
box = box_with_array | ||
xbox = np.ndarray if box is pd.array else box | ||
|
@@ -1761,6 +1763,11 @@ def test_td64arr_floordiv_td64arr_with_nat(self, box_with_array): | |
|
||
expected = np.array([1.0, 1.0, np.nan], dtype=np.float64) | ||
expected = tm.box_expected(expected, xbox) | ||
if box is DataFrame and using_array_manager: | ||
# INFO(ArrayManager) floorfiv returns integer, and ArrayManager | ||
# performs ops column-wise and thus preserves int64 dtype for | ||
# columns without missing values | ||
expected[[0, 1]] = expected[[0, 1]].astype("int64") | ||
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. why is expected different and is one behavior more desirable than the other? 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. ArrayManager performs the op column-wise, and thus can preserve dtypes (floordiv gives ints). Will add a comment about it in the line of https://github.com/pandas-dev/pandas/pull/39753/files#r576350947 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. thanks |
||
|
||
result = left // right | ||
|
||
|
@@ -2040,7 +2047,9 @@ def test_td64arr_rmul_numeric_array(self, box_with_array, vector, any_real_dtype | |
[np.array([20, 30, 40]), pd.Index([20, 30, 40]), Series([20, 30, 40])], | ||
ids=lambda x: type(x).__name__, | ||
) | ||
def test_td64arr_div_numeric_array(self, box_with_array, vector, any_real_dtype): | ||
def test_td64arr_div_numeric_array( | ||
self, box_with_array, vector, any_real_dtype, using_array_manager | ||
): | ||
# GH#4521 | ||
# divide/multiply by integers | ||
xbox = get_upcast_box(box_with_array, vector) | ||
|
@@ -2075,6 +2084,15 @@ def test_td64arr_div_numeric_array(self, box_with_array, vector, any_real_dtype) | |
expected = [tdser[n] / vector[n] for n in range(len(tdser))] | ||
expected = pd.Index(expected) # do dtype inference | ||
expected = tm.box_expected(expected, xbox) | ||
|
||
if using_array_manager and box_with_array is pd.DataFrame: | ||
# TODO the behaviour is buggy here (third column with all-NaT | ||
# as result doesn't get preserved as timedelta64 dtype). | ||
# Reported at https://github.com/pandas-dev/pandas/issues/39750 | ||
# Changing the expected instead of xfailing to continue to test | ||
# the correct behaviour for the other columns | ||
expected[2] = Series([pd.NaT, pd.NaT], dtype=object) | ||
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. this is sub-optimal. can you add a TODO to try to retain the correct dtype 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 fully understand your comment. Of course it's sub-optimal, as it's a bug (but an existing one, and I opened an issue about it) 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.
now im confused; we only get here if 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.e. if the expected isnt actually what we want, better to xfail 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.
Yes, I "uncovered" the bug by adding array manager tests, but the bug itself is not related to ArrayManager, it's a bug in TimedeltaArray (and you can run into it without ArrayManager as well, just not covered by any test) But indeed, an xfail might be more appropriate since I am now asserting the buggy behaviour. The problem is that I would then no longer test the other parts of this test (the other columns) which is actually working fine. 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. ok can you open an issue to address this in BM. (and ideally an INFO / TODO) for future reference. I am getting increasinly worried that things are changed, but we have no idea where except for PR comments, which are not very useful forward looking. 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. As mentioned above, and already included in the comment as well, I already opened an issue (it's #39750) 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.
OK. Can you add a non-ArrayManager test that will hit it? 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 added additional examples that don't involve ArrayManager to the issue (#39750) |
||
|
||
tm.assert_equal(result, expected) | ||
|
||
with pytest.raises(TypeError, match=pattern): | ||
|
Uh oh!
There was an error while loading. Please reload this page.