Skip to content

BUG: use more generic type inference for fast plotting #15094

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 1 commit into from
Jan 12, 2017

Conversation

jreback
Copy link
Contributor

@jreback jreback commented Jan 10, 2017

xref #15073

https://travis-ci.org/pandas-dev/pandas/jobs/190356982

was failing on tz-aware dtypes. these routines are the same in that they require datetime64ns (but any also accepts tz-aware).

@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Visualization plotting labels Jan 10, 2017
@jreback jreback added this to the 0.20.0 milestone Jan 10, 2017
@jreback
Copy link
Contributor Author

jreback commented Jan 10, 2017

@jorisvandenbossche

@codecov-io
Copy link

codecov-io commented Jan 10, 2017

Current coverage is 84.75% (diff: 90.90%)

Merging #15094 into master will increase coverage by <.01%

@@             master     #15094   diff @@
==========================================
  Files           145        145          
  Lines         51232      51234     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43420      43423     +3   
+ Misses         7812       7811     -1   
  Partials          0          0          

Powered by Codecov. Last update 0fe491d...c64b56b

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Good catch!
Forgot to look at the 'allowed failures' ..

@@ -172,7 +172,7 @@ def _dt_to_float_ordinal(dt):
is a :func:`float`.
"""
if (isinstance(dt, (np.ndarray, Index, Series)
) and is_datetime64_ns_dtype(dt)):
Copy link
Member

Choose a reason for hiding this comment

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

Theoretically, this is not fully correct, as is_datetime64_any_dtype can also accept datetime64 values with other than ns resolution?
Although I don't think you can end up here with such values when going through the DatetimeConverter, as datetime64 arrays first get passed through to_datetime

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Actually, we already have this:

        rs = self.dtc.convert(np.array([
            np_datetime64_compat('2012-01-01 00:00:00+0000'),
            np_datetime64_compat('2012-01-02 00:00:00+0000')]), None, None)
        self.assertEqual(rs[0], xp)

does already test this as the above has [s] resolution, not [ns] .

Would just add a test case for the tz case.

@jreback
Copy link
Contributor Author

jreback commented Jan 10, 2017

ok, I fixed is_datetime64_ns_dtype to work with tz-aware (as any does as well, this makes sense). let's see if anything else breaks. added a test as well.

@jreback
Copy link
Contributor Author

jreback commented Jan 11, 2017

ok, this is actually a tiny public API change, but it was inconsistent / wrong before.

@jreback
Copy link
Contributor Author

jreback commented Jan 11, 2017

@jorisvandenbossche

@jorisvandenbossche
Copy link
Member

How safe is it to change this? Couldn't there be places in our code where is_datetime64_ns_dtype is that assumes it has no timezone?

Just as overview, is this correct?

  • is_datetime64_dtype -> any resolution, no tz (pure numpy)
  • is_datetime64_any_dtype -> any resolution, with or without tz
  • is_datetime64tz_dtype -> ns? resolution, with tz (as other resolution with tz is not possible I think?)
  • is_datetime64_ns_dtype -> ns resolution, with or without tz

The combination missing is "ns resolution, no tz (pure numpy)", which is actually what is_datetime64_ns_dtype was before. But maybe we don't need this? (as you can use the tz one to check it has no timezone)

self.assertEqual(rs[1], xp)

rs = self.dtc.convert(ts, None, None)
self.assertEqual(rs, xp)
Copy link
Member

Choose a reason for hiding this comment

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

This seems duplicate of line 71-72 ?

Copy link
Member

Choose a reason for hiding this comment

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

Can you also add similar test for Index([ts - Day(1), ts]).to_pydatetime to test tz aware datetime.datetime objects (as this is actually what was raising the tests I think, as _mpl_repr() does return that).

self.assertTrue(is_datetime64_any_dtype('datetime64[ns]'))
self.assertTrue(is_datetime64_any_dtype(ts))
self.assertTrue(is_datetime64_any_dtype(tsa))

Copy link
Member

Choose a reason for hiding this comment

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

Can you do the exact same 4 tests for is_datetime64tz_dtype?

@jreback
Copy link
Contributor Author

jreback commented Jan 11, 2017

these functions are a bit redundant; the _ns_ and _any_ are barely used at all. so I don't think this is a big deal to change.

@jorisvandenbossche
Copy link
Member

Indeed, my search says that _any_ is exactly used in one spot, and _ns_ in three :-). So maybe rather something to clean-up? (but not for this PR)

@jreback
Copy link
Contributor Author

jreback commented Jan 11, 2017

@jorisvandenbossche yeah I'd leave them for now, they are useful, even if not used :>

pushing in a sec

@jreback
Copy link
Contributor Author

jreback commented Jan 12, 2017

@jorisvandenbossche

@jorisvandenbossche
Copy link
Member

yes!

@jorisvandenbossche jorisvandenbossche merged commit c9e7aee into pandas-dev:master Jan 12, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Visualization plotting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants