Skip to content

.ix indexing can't handle duplicate index values #1201

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
wesm opened this issue May 7, 2012 · 6 comments
Closed

.ix indexing can't handle duplicate index values #1201

wesm opened this issue May 7, 2012 · 6 comments
Labels
Milestone

Comments

@wesm
Copy link
Member

wesm commented May 7, 2012

(Pdb) result
      A   B   C   D
foo   2   3   4   5
bar   7   8   9  10
baz  12  13  14  15
qux  12  13  14  15
foo  12  13  14  15
bar  12  13  14  15
(Pdb) result.ix['bar']
*** Exception: Reindexing only valid with uniquely valued Index objects
@wesm wesm closed this as completed in e5490ef May 7, 2012
@binarybana
Copy link

I am still encountering this issue under 0.8.0, but now when trying to index with a list: (using the running example)

result.ix[['qux']]
Exception: Reindexing only valid with uniquely valued Index objects

@wesm wesm reopened this Jul 4, 2012
@wesm wesm closed this as completed in 4406d37 Jul 12, 2012
@sthornington
Copy link

Not sure if this is the same, but I am getting this error in 0.8 vs 0.8b2 (I believe), when doing:

new_data = Panel(new_data).swapaxes(0, 2)

where new_data was just read using a DataReader.

Call stack:

Traceback (most recent call last):
File "load_data.py", line 34, in
new_data = Panel(new_data).swapaxes(0, 2)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0-py2.7-macosx-10.6-intel.egg/pandas/core/panel.py", line 219, in init
mgr = self._init_dict(data, passed_axes, dtype=dtype)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0-py2.7-macosx-10.6-intel.egg/pandas/core/panel.py", line 271, in _init_dict
v = v.reindex(index=major, columns=minor, copy=False)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0-py2.7-macosx-10.6-intel.egg/pandas/core/frame.py", line 2122, in reindex
fill_value, limit)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0-py2.7-macosx-10.6-intel.egg/pandas/core/frame.py", line 2198, in _reindex_index
limit=limit)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0-py2.7-macosx-10.6-intel.egg/pandas/core/index.py", line 791, in reindex
limit=limit)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.8.0-py2.7-macosx-10.6-intel.egg/pandas/core/index.py", line 712, in get_indexer
raise Exception('Reindexing only valid with uniquely valued Index '
Exception: Reindexing only valid with uniquely valued Index objects

@wesm
Copy link
Member Author

wesm commented Aug 8, 2012

Can you test vs. 0.8.1?

@sthornington
Copy link

I cannot reproduce it with 0.8.1.

@wesm
Copy link
Member Author

wesm commented Aug 16, 2012

Okay. I'm fairly certain you hit a bug in which Yahoo! finance started returning duplicate dates.

@kevinwkc
Copy link

kevinwkc commented Jan 1, 2018

I'm using yahoo finance , it was working yesterday, but today is not working:

InvalidIndexError Traceback (most recent call last)
in get_historical(ticker, start_date, end_date)
67 return pivoted
68 '''
---> 69 p = web.DataReader(ticker, 'yahoo', start_date, end_date)
70 c = p['Adj Close'] #p['Close'] #
71 v = p['Volume']

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas_datareader\data.pyc in DataReader(name, data_source, start, end, retry_count, pause, session, access_key)
119 adjust_price=False, chunksize=25,
120 retry_count=retry_count, pause=pause,
--> 121 session=session).read()
122
123 elif data_source == "yahoo-actions":

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas_datareader\yahoo\daily.pyc in read(self)
113 """ read one data from specified URL """
114 try:
--> 115 df = super(YahooDailyReader, self).read()
116 if self.ret_index:
117 df['Ret_Index'] = _calc_return_index(df['Adj Close'])

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas_datareader\base.pyc in read(self)
184 df = self._dl_mult_symbols(self.symbols.index)
185 else:
--> 186 df = self._dl_mult_symbols(self.symbols)
187 return df
188

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas_datareader\yahoo\daily.pyc in _dl_mult_symbols(self, symbols)
146 for sym in failed:
147 stocks[sym] = df_na
--> 148 return Panel(stocks).swapaxes('items', 'minor')
149 except AttributeError:
150 # cannot construct a panel with just 1D nans indicating no data

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\panel.pyc in init(self, data, items, major_axis, minor_axis, copy, dtype)
146
147 self._init_data(data=data, items=items, major_axis=major_axis,
--> 148 minor_axis=minor_axis, copy=copy, dtype=dtype)
149
150 def _init_data(self, data, copy, dtype, **kwargs):

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\panel.pyc in _init_data(self, data, copy, dtype, **kwargs)
171 mgr = data
172 elif isinstance(data, dict):
--> 173 mgr = self._init_dict(data, passed_axes, dtype=dtype)
174 copy = False
175 dtype = None

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\panel.pyc in _init_dict(self, data, axes, dtype)
212 # extract axis for remaining axes & create the slicemap
213 raxes = [self._extract_axis(self, data, axis=i) if a is None else a
--> 214 for i, a in enumerate(axes)]
215 raxes_sm = self._extract_axes_for_slice(self, raxes)
216

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\panel.pyc in _extract_axis(self, data, axis, intersect)
1464
1465 if have_frames:
-> 1466 index = _get_combined_index(indexes, intersect=intersect)
1467
1468 if have_raw_arrays:

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\indexes\api.pyc in _get_combined_index(indexes, intersect)
41 index = index.intersection(other)
42 return index
---> 43 union = _union_indexes(indexes)
44 return _ensure_index(union)
45

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\indexes\api.pyc in _union_indexes(indexes)
72
73 if hasattr(result, 'union_many'):
---> 74 return result.union_many(indexes[1:])
75 else:
76 for other in indexes[1:]:

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\indexes\datetimes.pyc in union_many(self, others)
1044 else:
1045 tz = this.tz
-> 1046 this = Index.union(this, other)
1047 if isinstance(this, DatetimeIndex):
1048 this.tz = tz

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\indexes\base.pyc in union(self, other)
2173 result.extend([x for x in other._values if x not in value_set])
2174 else:
-> 2175 indexer = self.get_indexer(other)
2176 indexer, = (indexer == -1).nonzero()
2177

C:\Users\kevin\AppData\Local\conda\conda\envs\py27\lib\site-packages\pandas\core\indexes\base.pyc in get_indexer(self, target, method, limit, tolerance)
2581
2582 if not self.is_unique:
-> 2583 raise InvalidIndexError('Reindexing only valid with uniquely'
2584 ' valued Index objects')
2585

InvalidIndexError: Reindexing only valid with uniquely valued Index objects

THANK YOU

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants