-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
errors and inconsistent behaviour when using a DataFrame or a boolean Series as an index #18579
Comments
@robbuckley not really clear why you would do this, e.g. pass a DataFrame to an Index. I believe we are going to raise on this (just discussing with @toobaz can't quite find the issue). And a boolean index is a quite strange beast. |
@robbuckley three things are sure:
The rest is a bit less obvious. Boolean indexes are strange beasts at least for the general reason that non-unique indexes are strange beasts. But I personally think we will end up supporting them, for consistency (in particular with unstacking of boolean levels from This said, even if not introducing a |
@toobaz yeah I'll repurpose this issue a bit to enhance error reporting w.r.t. nested-list likes to |
Sorry, I totally misunderstood the original report, so my point "if you pass something as index=something, it should not go in the Series values" made no sense. Let me try again:
the discussion on |
@jreback i dont have a specific use case, I just stumbled across it. IMHO they should either raise early or be supported in a consistent way. It would be in the spirit of the docs to use s.values for all cases, casting df.values into a multiindex. But a raise on any attempt to use a Series or df as an index would be better than the current behaviour, i think Currently the constructors succeed for all these examples, but various things fail down the line, in more or less confusing ways -- except for the integer Series example, where it behaves as if s.index were passed. The dataframe case is especially confusing - at a first [careless] glance, it appears to have kind-of worked -- s.index looks as if it has 2x1 ndarrays as the keys. But in fact s.index.values is a 2x3 ndarray and bad things happen when i try to do other things with the series. |
These looks reasonable on master. Could use a test
|
Code Sample, a copy-pastable example if possible
so far so good, now lets try a boolean series
now a dataframe
Problem description
I would expect passing a boolean Series as the index= parameter to either act as Series.index (as in the example where the integer Series s1 is used as an index) or Series.values (as the docs seem imply http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html "index : array-like or Index (1d)")
For the DataFrame case, it could either use df.index, or fail early with a ValueError
[this should explain why the current behaviour is a problem and why the expected output is a better solution.]
Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!
Note: Many problems can be resolved by simply upgrading
pandas
to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check ifmaster
addresses this issue, but that is not necessary.For documentation-related issues, you can check the latest versions of the docs on
master
here:https://pandas-docs.github.io/pandas-docs-travis/
If the issue has not been resolved there, go ahead and file it in the issue tracker.
Expected Output
either
OR
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit: None
python: 3.5.4.final.0
python-bits: 64
OS: Darwin
OS-release: 17.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.4.0
Cython: 0.26
numpy: 1.12.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: