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/11586 below:

.loc against CategoricalIndex may result in normal Index · Issue #11586 · pandas-dev/pandas · GitHub

.loc against CategoricalIndex with values included in its categories but not appears as codes results in normal Index

import numpy as np
import pandas as pd

index = pd.CategoricalIndex(list('aabbca'), categories=list('cabe'))
df = pd.DataFrame({'A' : np.arange(6,dtype='int64')}, index=index)

# OK
df.loc[['a', 'b']].index
# CategoricalIndex([u'a', u'a', u'a', u'b', u'b'], categories=[u'c', u'a', u'b', u'e'], ordered=False, dtype='category')

# NG, must be CategoricalIndex
df.loc[['a', 'b', 'e']].index
# Index([u'a', u'a', u'a', u'b', u'b', u'e'], dtype='object')

Even though this is tested here, it doesn't check dtype.


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