Skip to content
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: strict xfail #38960

Merged
merged 6 commits into from
Jan 9, 2021
Merged

TST: strict xfail #38960

merged 6 commits into from
Jan 9, 2021

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented Jan 4, 2021

  • Ensure all linting tests pass, see here for how to run them

Part of #38902.

@rhshadrach rhshadrach added the Testing pandas testing functions or related to the test suite label Jan 4, 2021
@rhshadrach rhshadrach marked this pull request as draft January 4, 2021 23:38
@@ -466,8 +466,6 @@ def test_insert_index_datetimes(self, fill_val, exp_dtype):
with pytest.raises(TypeError, match=msg):
obj.insert(1, 1)

pytest.xfail("ToDo: must coerce to object")
Copy link
Member

Choose a reason for hiding this comment

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

i think this indicates something that we need to fix. maybe should write out the assertion so that the xfail is meaningful

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @jbrockmendel, I was planning on pinging you and @WillAyd after a bit more digging into this, but you beat me to it :). This was originally changed in #18721 from a comment to the xfail that exists now. The comments were originally added
in 7c0b742. I'm not sure what should be asserted here; from the history it seems like it refers to the tests above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also note those comments still exist in the test immediately below.

Copy link
Member

Choose a reason for hiding this comment

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

if we want to coerce to object (and i think we do), then for starters the insert on L467 shouldn't raise but should instead be equivalent to obj.astype(object).insert(1, 1). so i think can just change that and then xfail it?

the harder question is what we do in the two cases above that with mismatched tz or mismatched tzawareness. with mismatched tz could just cast (#37605), with mismatched tzawareness could also cast to object.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you can create an issue for this in followup (and PR if you can!)

@rhshadrach
Copy link
Member Author

@jbrockmendel I adjusted the coercion test, let me know what you think.

For the offset test, the value 1000 causes the OutOfBounds exception for Week, Month, etc but not Day. Since the exception is caught, this makes the Day test pass even on 32-bit. One possible resolution is to move the xfail test down (current state of this PR), but I think better would be to find appropriate numbers for the different classes so that we can remove the except OutOfBounds entirely. Wanted to see what you thought first before I did so.

@rhshadrach
Copy link
Member Author

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@jreback jreback added this to the 1.3 milestone Jan 6, 2021
@jreback
Copy link
Contributor

jreback commented Jan 6, 2021

lgtm. cc @jbrockmendel

@rhshadrach
Copy link
Member Author

I've looked into implementing my suggested approach in #38960 (comment) but don't see any way of deducing a good value except hard coding on a case-by-case basis. I'll do so if that's desired, but it doesn't seem like a good change to me.

@rhshadrach rhshadrach marked this pull request as ready for review January 9, 2021 17:40
@jbrockmendel
Copy link
Member

way of deducing a good value

# for cls in pd.offsets.Tick.__subclasses__():
cls = pd.offsets.Day
bound = np.iinfo(np.int64).max  # might be np.intp if 32bit is the issue?
nmax = bound // cls(1).nanos

pd.Timedelta(cls(nmax))  # <- works
pd.Timedelta(cls(nmax + 1))   # <- raises

is that what you're looking for?

@@ -466,8 +466,6 @@ def test_insert_index_datetimes(self, fill_val, exp_dtype):
with pytest.raises(TypeError, match=msg):
obj.insert(1, 1)

pytest.xfail("ToDo: must coerce to object")
Copy link
Contributor

Choose a reason for hiding this comment

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

if you can create an issue for this in followup (and PR if you can!)

@jreback jreback merged commit 094b09c into pandas-dev:master Jan 9, 2021
@rhshadrach
Copy link
Member Author

Thanks @jbrockmendel, that is indeed what I was going for. However reviewing the test again, I think I'm confused on what this test is trying to do. From the comment:

try to create an out-of-bounds result timestamp; if we can't create
the offset skip

I was under the impression that the test would create an offset large enough so that when it was added to the TimeStamp it would raise an OutOfBoundsDatetime. If this was the case, then one would be expecting the line

result = Timestamp("20080101") + offset

to raise. But there are several lines of testing after this, which is why I'm pretty sure I'm missing the point of this test.

@rhshadrach
Copy link
Member Author

rhshadrach commented Jan 10, 2021

I was thinking the test could be written something like this:

        # try to create an out-of-bounds result timestamp

        ts = Timestamp("20080101")
        max_seconds = (ts.max - ts).total_seconds()
        offset_100 = self._get_offset(self._offset, value=100)
        seconds = ((ts + offset_100) - ts).total_seconds() / 100
        # Add a small buffer since we're taking an average
        value = int(max_seconds / seconds) + 10
        offset = self._get_offset(self._offset, value=value)

        with pytest.raises(OutOfBoundsDatetime):
            _ = ts + offset

luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
@jbrockmendel
Copy link
Member

@rhshadrach sorry this fell through the cracks of my inbox. is the _get_offset thing still an issue?

@rhshadrach
Copy link
Member Author

@jbrockmendel - Not a problem, thanks for getting back. I'm really not sure - if my understanding of the test is correct, I think it could be streamlined a bit (and I'd be happy to do), but I have strong suspicions I don't really understand what the test is testing. I tried to explain this in #38960 (comment). If that comment isn't clear, let me know and I can try again.

@jbrockmendel
Copy link
Member

But there are several lines of testing after this, which is why I'm pretty sure I'm missing the point of this test.

Best guess, IIRC there was at one point (maybe still is) some part of the offsets code that would work with pydatetimes instead of Timestamps. Could be that part of the test was intended for those?

@rhshadrach rhshadrach deleted the xfail_strict_3 branch February 2, 2021 22:20
@rhshadrach
Copy link
Member Author

Thanks @jbrockmendel - I finally was able to track down the original implementation of this test in #5327:

    def test_apply_out_of_range(self):
        if self._offset is None:
            raise nose.SkipTest("_offset not defined")

        # try to create an out-of-bounds result timestamp; if we can't create the offset
        # skip
        try:
            offset = self._offset(10000)

            result = Timestamp('20080101') + offset
            self.assert_(isinstance(result, datetime))
        except (OutOfBoundsDatetime):
            raise
        except (ValueError, KeyError):
            raise nose.SkipTest("cannot create out_of_range offset")

Notice here we raise on OutOfBoundsDatetime. The release note from that PR was:

Allows operating of Timestamps to return a datetime if the result is out-of-bounds related

The test I proposed above passes all checks (namely, can always construct an offset that when added to a Timestamp will raise an OutOfBoundsDatetime). I'm thinking that the behavior of returning a datetime is no longer the case and wondering if the test above should be used instead.

@jbrockmendel
Copy link
Member

I'm thinking that the behavior of returning a datetime is no longer the case and wondering if the test above should be used instead.

there may be some legacy compat code in there, but i don't think we support pydatetime in any kind of consistent way at this point

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.

3 participants