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

BUG: Index may ignore specified datetime/timedelta dtypes #13981

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Aug 13, 2016

  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry

Index ignores specified dtype if it is datetime64 (normal and tz) or timedelta64. This PR makes it consistent with DatetimeIndex and TimedeltaIndex.

pd.Index([1, 2, 3], dtype='datetime64[ns, US/Eastern]')
# Index([1, 2, 3], dtype='object')
pd.Index([1, 2, 3], dtype='datetime64[ns]')
# Index([1, 2, 3], dtype='object')
pd.Index([1, 2, 3], dtype='timedelta64[ns]')
# Int64Index([1, 2, 3], dtype='int64')

Also, fixed MultiIndex.get_level_values not to pass unnecessary tz and freq.

@sinhrks sinhrks added Bug Datetime Datetime data dtype Timedelta Timedelta data type labels Aug 13, 2016
@sinhrks sinhrks added this to the 0.19.0 milestone Aug 13, 2016
@sinhrks sinhrks added the Dtype Conversions Unexpected or buggy dtype conversions label Aug 13, 2016
@codecov-io
Copy link

codecov-io commented Aug 13, 2016

Current coverage is 85.27% (diff: 100%)

Merging #13981 into master will decrease coverage by 0.01%

@@             master     #13981   diff @@
==========================================
  Files           139        139          
  Lines         50206      50205     -1   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          42818      42810     -8   
- Misses         7388       7395     +7   
  Partials          0          0          

Powered by Codecov. Last update 29d9e24...a922aef

@jreback jreback closed this in 3760f16 Aug 13, 2016
@jreback
Copy link
Contributor

jreback commented Aug 13, 2016

thanks!

@sinhrks sinhrks deleted the index_init_datetimelike branch August 13, 2016 23:02
@jorisvandenbossche
Copy link
Member

@sinhrks Is it correct that you introduced the tz keyword in Index in this PR?
Personally I don't think this is needed (it is also not documented).

To be clear, the fact that dtype is no longer ignored in Index is a nice bug fix! My comment is only about the tz keyword.

@jreback
Copy link
Contributor

jreback commented Aug 13, 2016

tz is NOT in the Index signature but you can pass kwargs generally

@sinhrks
Copy link
Member Author

sinhrks commented Aug 13, 2016

@jorisvandenbossche prior to this PR, passing tz kwd coerces to DatetimeIndex in some cases. This PR makes it consistent.

@jorisvandenbossche
Copy link
Member

tz was previously passed through to when you already had datetime data, eg:

In [10]: pd.Index([datetime.datetime(2012,1,1), datetime.datetime(2012,1, 2)], tz="Europe/Brussels")
Out[10]: DatetimeIndex(['2012-01-01 00:00:00+01:00', '2012-01-02 00:00:00+01:00'], dtype='datetime64[ns, Europe/Brussels]', freq=None)

But the consequence of this PR is that for example the following now also works:

In [82]: pd.Index([1, 2], tz="Europe/Brussels")
Out[82]: DatetimeIndex(['1970-01-01 00:00:00+01:00', '1970-01-01 00:00:00+01:00'], dtype='datetime64[ns, Europe/Brussels]', freq=None)

I personally don't think this should work like that .. (a bit too much magic).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Dtype Conversions Unexpected or buggy dtype conversions Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants