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.

What to do with future Ambiguity Error about overlapping names when sorting?

See original GitHub issue

xref https://github.com/pandas-dev/pandas/pull/17361

In [24]: df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}, index=pd.Index([1, 2], name='a'))

In [25]: df.sort_values(['a', 'b'])
/Users/taugspurger/.virtualenvs/pandas-dev/bin/ipython:1: FutureWarning: 'a' is both an index level and a column label.
Defaulting to column, but this will raise an ambiguity error in a future version
  #!/Users/taugspurger/Envs/pandas-dev/bin/python3
Out[25]:
   a  b
a
1  1  3
2  2  4

What should the user do in this situation? Should we provide a keyword to disambiguate? A literal like pd.ColumnLabel('a') or pd.IndexName('a')? Or do we require that they rename an index or column? Right now, they’re essentially stuck with the last one. If we want to discourage that, then I suppose that’s OK. But it’s somewhat common to end up with overlapping names, from e.g. a groupby.

cc @jmmease

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
TomAugspurgercommented, May 16, 2018

To be clear, I’m OK with going down this road of “indexes are a special type of column, so don’t have overlapping names”. Perhaps we’ll use this issue to collect use-cases where they arise, and document how to avoid them?

e.g. the last one would be something like “use groupby('a', as_index=False)”.

3reactions
xieyuhengcommented, Jan 18, 2019

It is not ambiguous when I specify axis=0.

df = pd.DataFrame({"a": [1, 2], "b": [3, 4]}, index=pd.Index([1, 2], name='a'))

df.sort_values(['a', 'b'], axis=0)

But the warning still.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merge, join, concatenate and compare - Pandas
This will result in an ambiguity error in a future version. Overlapping value columns#. The merge suffixes argument takes a tuple of list...
Read more >
A PivotTable report cannot overlap another ... - MyExcelOnline
Steps To Fix Overlapping Pivot Tables in Excel. DOWNLOAD EXCEL WORKBOOK. STEP 1: Let us see the error in action. Right click on...
Read more >
Merge with Caution: How to Avoid Common Problems ... - SAS
This paper examines several common issues, provides examples to illustrate what can go wrong and why, and discusses best practices to avoid unintended ......
Read more >
Innovations and challenges in detecting long read overlaps
These error-corrected reads can then be overlapped again with higher ... Though the computational cost incurred by sorting the list can negatively impact ......
Read more >
XSL Transformations (XSLT) Version 3.0 - W3C
As an implementer option, XSLT 3.0 can also be used with XPath 3.1. ... There is no ambiguity, and no error, if several...
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