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.

Un-deprecate DataFrame.from_items()

See original GitHub issue

Under #18262 a FutureWarning was added suggesting that existing code like this:

pd.DataFrame.from_items(x)

Should be changed to this:

import collections
pd.DataFrame.from_dict(collections.OrderedDict(x))

The fact that from_items() appeared only 6 times (now 8 times) in a Stack Overflow search was used as partial justification for removing it. But if you search on GitHub, pd.DataFrame.from_items() appears more than 15,000 times in Python–almost half as many as from_records()!

We should celebrate the fact that this function doesn’t cause enough confusion to appear often on Stack Overflow. But it does occur (a lot!) in real code, and deprecating it is a mistake.

If constructing a temporary OrderedDict around items is the best way to construct a DataFrame, Pandas should implement that as a short function called DataFrame.from_items(), rather than asking thousands of people to busy themselves to accommodate this unnecessary API change.

I recommend removing the FutureWarning, and retaining this widely-used, longstanding function.

For reference, the FutureWarning starts in 0.23 and looks like this:

FutureWarning: from_items is deprecated. Please use DataFrame.from_dict(dict(items), …) instead. DataFrame.from_dict(OrderedDict(items)) may be used to preserve the key order.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:22 (19 by maintainers)

github_iconTop GitHub Comments

4reactions
jzwinckcommented, Jul 26, 2018

@jreback It is clear that you think this is a good deprecation, otherwise you would not have done it. However, the initial justification (“only 6 hits on Stack Overflow”) completely ignored the larger picture, which is that this function is widely used in a huge number of applications and libraries.

It might be the case that the original implementation was unwieldy or costly to maintain. But what could be the reason not to maintain backward compatibility by a 3-line function that delegates the work to OrderedDict and the main DataFrame constructor?

In other words, maybe the old code was not helpful. Would you accept new code to implement this widely-used function in a single place, rather than having thousands of users sprinkle the same into their local codebases?

3reactions
PatrickDRuskcommented, Sep 14, 2018

I haven’t seen any mention that the from_dict(OrderedDict(items)... doesn’t work in cases where there would be duplicates in the index. Here is a test that would fail:

import pandas
from collections import OrderedDict
def test_from_dict_replacing_from_items():
    rows = [(1, (2,)), (1, (2,))]
    df1 = pandas.DataFrame.from_items(rows, columns=('a', ), orient='index')
    df2 = pandas.DataFrame.from_dict(OrderedDict(rows), columns=('a', ), orient='index')
    pandas.testing.assert_frame_equal(df1, df2)
Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.DataFrame.from_items — pandas 0.23.1 documentation
Deprecated since version 0.23.0: from_items is deprecated and will be removed in a future version. Use DataFrame.from_dict(dict(items)) instead.
Read more >
Source code for pandas.core.frame
[docs] def from_records(cls, data, index=None, exclude=None, columns=None, coerce_float=False, nrows=None): ... to_wide = deprecate('to_wide', to_panel).
Read more >
Depricated method from_items throws error when changed to ...
For me working nice convert it to dictionary: df = pd.DataFrame(dict(Test_Data)) #another alternative solution #df = pd.DataFrame({a:b for a ...
Read more >
Excel “Filter and Edit” - Demonstrated in Pandas
DataFrame.from_items(sales) ... df["commission"] = .02 df.head() ... and round the results by sales rep df.groupby(["sales rep"])["comp"].sum().round(2)
Read more >
wiseio - Bountysource
Similar to the chunksize parameter of pandas.read_csv(). ... Eventually we can deprecate the existing CSV reader in pandas and make 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