question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make pd.Series(index=values) equivalent to pd.Series(index=pd.Index(values))?

See original GitHub issue

Code Sample, a copy-pastable example if possible

In [2]: d = {(0, 1) : 2, (3, 4) : 5}

In [3]: pd.Index(d)
Out[3]: Index([(0, 1), (3, 4)], dtype='object')

In [4]: pd.Index(list(d))
Out[4]: 
MultiIndex(levels=[[0, 3], [1, 4]],
           labels=[[0, 1], [0, 1]])

In [5]: pd.Series(d).index
Out[5]: 
MultiIndex(levels=[[0, 3], [1, 4]],
           labels=[[0, 1], [0, 1]])

In [6]: pd.Series(index=list(d)).index
Out[6]: Index([(0, 1), (3, 4)], dtype='object')

Problem description

I guess Out[3]: and Out[6]: are wrong.

Expected Output

Out[4]:

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None python: 3.5.3.final.0 python-bits: 64 OS: Linux OS-release: 4.9.0-4-amd64 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8

pandas: 0.22.0.dev0+202.g97bd66ea8 pytest: 3.0.6 pip: 9.0.1 setuptools: 33.1.1 Cython: 0.25.2 numpy: 1.12.1 scipy: 0.18.1 pyarrow: None xarray: None IPython: 5.2.2 sphinx: None patsy: 0.4.1+dev dateutil: 2.6.0 pytz: 2016.10 blosc: None bottleneck: 1.2.0 tables: 3.3.0 numexpr: 2.6.1 feather: 0.3.1 matplotlib: 2.0.0 openpyxl: 2.3.0 xlrd: 1.0.0 xlwt: 1.2.0 xlsxwriter: None lxml: 3.7.1 bs4: 4.5.3 html5lib: 0.999999999 sqlalchemy: 1.0.15 pymysql: None psycopg2: None jinja2: 2.8 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Nov 28, 2017

[2] is invalid but prob not checked

these are not hashable sub elements

absolutely we do not want to add complexity like this

0reactions
jrebackcommented, Nov 29, 2017

suppress _ensure_index, which becomes redundant (since it seems to me it isn’t catching any other case)

the original intent of _ensure_index was I think to infer whether things should be an Index or a MultiIndex. If you can remove code great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indexing and selecting data — pandas 1.5.2 documentation
A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above). See...
Read more >
pandas.Index — pandas 1.5.2 documentation
A NumPy ndarray representing the values in this Series or Index. to_series ([index, name]). Create a Series with both index and values equal...
Read more >
pandas.Series — pandas 1.5.2 documentation
After this the Series is reindexed with the given Index values, hence we get all NaN as a ... Return boolean Series equivalent...
Read more >
pandas.Series.index — pandas 1.5.2 documentation
Series.index#. Series.index#. The index (axis labels) of the Series.
Read more >
pandas.Series.reindex — pandas 1.5.2 documentation
A new object is produced unless the new index is equivalent to the ... Broadcast across a level, matching Index values on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found