Skip to content

BUG: Add import for 'is_datetime64_dtype' #3920

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

Closed
wants to merge 1 commit into from

Conversation

jtratner
Copy link
Contributor

This import was missing from core/groupby.py. This also suggests that there is an issue with the test cases, given that no test triggers this issue (suggesting that there is no current test that triggers the elif condition below).

    def _try_cast(self, result, obj):
        """ try to cast the result to our obj original type,
        we may have roundtripped thru object in the mean-time """
        try:
            if obj.ndim > 1:
                dtype = obj.values.dtype
            else:
                dtype = obj.dtype

            if _is_numeric_dtype(dtype):

                # need to respect a non-number here (e.g. Decimal)
                if len(result) and issubclass(type(result[0]),(np.number,float,int)):
                    result = _possibly_downcast_to_dtype(result, dtype)

            elif issubclass(dtype.type, np.datetime64):
                if is_datetime64_dtype(obj.dtype):
                    result = result.astype(obj.dtype)

@cpcloud
Copy link
Member

cpcloud commented Jun 16, 2013

u could run coverage and see if it agrees with your suggestion

@jtratner
Copy link
Contributor Author

@cpcloud Not necessary - the missing import is on master, if all the tests pass with the missing import, the line can't ever have been executed during the tests.

@cpcloud
Copy link
Member

cpcloud commented Jun 16, 2013

ah yes indeed

@jreback
Copy link
Contributor

jreback commented Jun 16, 2013

Looking at this now

this can only be hit if the datetimes are not views and not datetime64[ns]
sometime which is not possible
I don't recall what happens to dt during groupby exactly ( whether they r converted with a view or not)

@jtratner
Copy link
Contributor Author

Do you want to remove the line altogether?

On Sun, Jun 16, 2013 at 6:54 AM, jreback [email protected] wrote:

Looking at this now

this can only be hit if the datetimes are not views and not datetime64[ns]
sometime which is not possible
I don't recall what happens to dt during groupby exactly ( whether they r
converted with a view or not)


Reply to this email directly or view it on GitHubhttps://github.com//pull/3920#issuecomment-19510774
.

@jreback
Copy link
Contributor

jreback commented Jun 16, 2013

I am not sure it is ever hit (as u have noticed)
let me see if I can figure out what it's supposed to do

@cpcloud
Copy link
Member

cpcloud commented Jun 17, 2013

@jreback any luck here?

@jreback
Copy link
Contributor

jreback commented Jun 17, 2013

tomorrow

@jreback
Copy link
Contributor

jreback commented Jun 17, 2013

this was being called incorrectly (and uncessarily), then trapped by try: except, all fixed up; closing this PR (fixed in #3934)...thanks for finding this!

@jreback jreback closed this Jun 17, 2013
@jtratner jtratner deleted the fix-missing-import branch June 17, 2013 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants