Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
221bd87
tests not passing but i need to rebase again
jbrockmendel May 21, 2021
1f45dbd
API: make concat_compat behave like CategoricalIndex._concat
jbrockmendel Aug 4, 2021
d68f868
Merge branch 'master' into ci-concat
jbrockmendel Nov 9, 2021
4cc59c7
Merge branch 'master' into ci-concat
jbrockmendel Nov 23, 2021
53d3aea
Merge branch 'master' into ci-concat
jbrockmendel Nov 25, 2021
329d2ba
Merge branch 'master' into ci-concat
jbrockmendel Nov 26, 2021
abdd2a8
avoid FutureWarning
jbrockmendel Nov 26, 2021
6b9a75e
Merge branch 'master' into ci-concat
jbrockmendel Dec 5, 2021
ac7debd
Merge branch 'master' into ci-concat
jbrockmendel Dec 6, 2021
94976da
Merge branch 'master' into ci-concat
jbrockmendel Dec 12, 2021
6b2c55d
Merge branch 'master' into ci-concat
jbrockmendel Dec 26, 2021
bb6aa1a
Merge branch 'master' into ci-concat
jbrockmendel Dec 27, 2021
3120e51
Merge branch 'master' into ci-concat
jbrockmendel Dec 27, 2021
84fed7a
Merge branch 'master' into ci-concat
jbrockmendel Jan 1, 2022
8e58449
Merge branch 'master' into ci-concat
jbrockmendel Jan 1, 2022
8e9f60a
Merge branch 'master' into ci-concat
jbrockmendel Jan 6, 2022
9164016
avoid append
jbrockmendel Jan 6, 2022
7ba8d2d
catch warnings
jbrockmendel Jan 6, 2022
6daccec
Merge branch 'master' into ci-concat
jbrockmendel Jan 7, 2022
75ab0a0
ArrayManager compat
jbrockmendel Jan 7, 2022
1f6ac46
Merge branch 'master' into ci-concat
jbrockmendel Jan 8, 2022
16481a0
Merge branch 'master' into ci-concat
jbrockmendel Jan 11, 2022
881f47f
Merge branch 'main' into ci-concat
jbrockmendel Jan 13, 2022
ee5dd27
Merge branch 'main' into ci-concat
jbrockmendel Jan 17, 2022
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
tests not passing but i need to rebase again
  • Loading branch information
jbrockmendel committed Aug 4, 2021
commit 221bd87bc228827dec941e8a895dac5da18b6a5f
14 changes: 14 additions & 0 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ def is_nonempty(x) -> bool:
if any_ea:
# we ignore axis here, as internally concatting with EAs is always
# for axis=0
if any(is_categorical_dtype(x.dtype) for x in to_concat):
first = [x for x in to_concat if is_categorical_dtype(x.dtype)][0]
from pandas import Index
try:
codes = np.concatenate([Index(first)._is_dtype_compat(Index(c)).codes for c in to_concat])
except TypeError:
# not all to_concat elements are among our categories (or NA)
pass
else:
cat = first._from_backing_data(codes)
if first.ordered:
cat = cat.as_ordered()
return cat

if not single_dtype:
target_dtype = find_common_type([x.dtype for x in to_concat])
to_concat = [cast_to_common_type(arr, target_dtype) for arr in to_concat]
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ def map(self, mapper):
return Index(mapped, name=self.name)

def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
alt = Index._concat(self, to_concat, name=name) # uses concat_compat

# if calling index is category, don't check dtype of others
try:
codes = np.concatenate([self._is_dtype_compat(c).codes for c in to_concat])
Expand All @@ -556,7 +558,11 @@ def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
from pandas.core.dtypes.concat import concat_compat

res = concat_compat(to_concat)
return Index(res, name=name)
out = Index(res, name=name)
assert out.equals(alt)
assert out.dtype == alt.dtype
return out
else:
cat = self._data._from_backing_data(codes)
assert cat.dtype == alt.dtype
return type(self)._simple_new(cat, name=name)
21 changes: 8 additions & 13 deletions pandas/tests/base/test_value_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def test_value_counts(index_or_series_obj):


@pytest.mark.parametrize("null_obj", [np.nan, None])
def test_value_counts_null(null_obj, index_or_series_obj):
@pytest.mark.parametrize("dropna", [True, False])
def test_value_counts_null(null_obj, dropna, index_or_series_obj):
orig = index_or_series_obj
obj = orig.copy()

Expand All @@ -70,20 +71,14 @@ def test_value_counts_null(null_obj, index_or_series_obj):
expected = Series(dict(counter.most_common()), dtype=np.int64)
expected.index = expected.index.astype(obj.dtype)

result = obj.value_counts()
if obj.duplicated().any():
# TODO:
# Order of entries with the same count is inconsistent on CI (gh-32449)
expected = expected.sort_index()
result = result.sort_index()
tm.assert_series_equal(result, expected)
if not dropna:
# can't use expected[null_obj] = 3 as
# IntervalIndex doesn't allow assignment
new_entry = Series({np.nan: 3}, dtype=np.int64)
expected = expected.append(new_entry)

# can't use expected[null_obj] = 3 as
# IntervalIndex doesn't allow assignment
new_entry = Series({np.nan: 3}, dtype=np.int64)
expected = expected.append(new_entry)
result = obj.value_counts(dropna=dropna)

result = obj.value_counts(dropna=False)
if obj.duplicated().any():
# TODO:
# Order of entries with the same count is inconsistent on CI (gh-32449)
Expand Down