Empty subtypes of Index return their type, rather than Index
State: closed

Resolves #10596 


Labels:
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Period
description: Period data type
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
@jreback I'm having some issues with comparing empty Indexes. For Timedelta, Datetime & Categorical, I get the equivalent of this: 

``` python
AssertionError: TimedeltaIndex([], dtype='timedelta64[ns]', freq='D') != TimedeltaIndex([], dtype='timedelta64[ns]', freq='D')
```

I'd love to take a look at the wider problem in the future; in the meantime is there a way of getting this fix in? Is there a strong reason you don't like the type test rather than the direct comparison?

no, use `idx1.equals(idx2)`

just asserting type papers over the meta data propogation, so its just creates a new bug, rather than fixing the existing one.

Great @jreback, that should be good to go. Let me know if I've missed anything. Cheers

pls add a release note in whatsnew/v0.17.0

squash to a single commit

ping when green.

I have a PyTables test fail - does anyone have any idea what this might be? I've dug around, but not getting anywhere fast; and have zero PyTables experience / installation.

``` python
ERROR: test_to_hdf_with_object_column_names (pandas.io.tests.test_pytables.TestHDFStore)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/pydata/pandas/pandas/io/tests/test_pytables.py", line 4678, in test_to_hdf_with_object_column_names
    df.to_hdf(path, 'df', format='table', data_columns=True)
  File "/home/travis/build/pydata/pandas/pandas/core/generic.py", line 920, in to_hdf
    return pytables.to_hdf(path_or_buf, key, self, **kwargs)
  File "/home/travis/build/pydata/pandas/pandas/io/pytables.py", line 269, in to_hdf
    f(store)
  File "/home/travis/build/pydata/pandas/pandas/io/pytables.py", line 264, in <lambda>
    f = lambda store: store.put(key, value, **kwargs)
  File "/home/travis/build/pydata/pandas/pandas/io/pytables.py", line 826, in put
    self._write_to_group(key, value, append=append, **kwargs)
  File "/home/travis/build/pydata/pandas/pandas/io/pytables.py", line 1275, in _write_to_group
    s.write(obj=value, append=append, complib=complib, **kwargs)
  File "/home/travis/build/pydata/pandas/pandas/io/pytables.py", line 3798, in write
    **kwargs)
  File "/home/travis/build/pydata/pandas/pandas/io/pytables.py", line 3404, in create_axes
    axis=axis
  File "/home/travis/build/pydata/pandas/pandas/core/frame.py", line 2522, in reindex_axis
    fill_value=fill_value)
  File "/home/travis/build/pydata/pandas/pandas/core/generic.py", line 1852, in reindex_axis
    limit=limit)
  File "/home/travis/build/pydata/pandas/pandas/core/index.py", line 3062, in reindex
    if not is_categorical_dtype(target) and not target.is_unique:
  File "properties.pyx", line 34, in pandas.lib.cache_readonly.__get__ (pandas/lib.c:39442)
  File "/home/travis/build/pydata/pandas/pandas/core/index.py", line 744, in is_unique
    return self._engine.is_unique
  File "index.pyx", line 213, in pandas.index.IndexEngine.is_unique.__get__ (pandas/index.c:4392)
  File "index.pyx", line 248, in pandas.index.IndexEngine._do_unique_check (pandas/index.c:4874)
  File "index.pyx", line 261, in pandas.index.IndexEngine._ensure_mapping_populated (pandas/index.c:5047)
  File "index.pyx", line 267, in pandas.index.IndexEngine.initialize (pandas/index.c:5135)
  File "hashtable.pyx", line 703, in pandas.hashtable.PyObjectHashTable.map_locations (pandas/hashtable.c:11242)
ValueError: Buffer dtype mismatch, expected 'Python object' but got 'double'
```

what are the columns on the df
(this is the point of the test - you can only have strong columns not numbers and such)

The columns are either strings or categoricals - that's the line this fails on. 
If you cut through to what this issue is, that'd be awesome. Otherwise I can try and install PyTables and debug from the bottom.

``` python
        types_should_run = [ tm.makeStringIndex, tm.makeCategoricalIndex ]
...
        for index in types_should_run:
            df = DataFrame(np.random.randn(10, 2), columns=index(2))
            with ensure_clean_path(self.path) as path:
                df.to_hdf(path, 'df', format='table', data_columns=True)
                result = pd.read_hdf(path, 'df', where="index = [{0}]".format(df.index[0]))
                assert(len(result))
```