A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/10587 below:

concat of same categoricals can be sped up · Issue #10587 · pandas-dev/pandas · GitHub

These are currently converted to object (and back) in _concat_compat. But if they are the same dtype (same categoriies/ordering), then this can be short-circutied.

In [17]: s = Series(list('aabbcd')*1000000).astype('category')

In [18]: result = pd.concat([s,s])

In [19]: result2 = Series(pd.Categorical(pd.concat([s.cat.codes,s.cat.codes]),s.cat.categories,fastpath=True))

In [20]: result = pd.concat([s,s],ignore_index=True)

In [21]: result2 = Series(pd.Categorical(pd.concat([s.cat.codes,s.cat.codes],ignore_index=True),s.cat.categories,fastpath=True))

In [22]: result.equals(result2)
Out[22]: True

In [23]: %timeit pd.concat([s,s],ignore_index=True)
1 loops, best of 3: 658 ms per loop

In [24]: %timeit Series(pd.Categorical(pd.concat([s.cat.codes,s.cat.codes],ignore_index=True),s.cat.categories,fastpath=True))
10 loops, best of 3: 52.3 ms per loop

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4