|
18 | 18 | from pandas.core.common import (
|
19 | 19 | ABCSeries, ABCIndexClass, ABCCategoricalIndex, isnull, notnull,
|
20 | 20 | is_dtype_equal, is_categorical_dtype, is_integer_dtype,
|
21 |
| - _possibly_infer_to_datetimelike, get_dtype_kinds, is_list_like, |
| 21 | + _possibly_infer_to_datetimelike, is_list_like, |
22 | 22 | is_sequence, is_null_slice, is_bool, _ensure_object, _ensure_int64,
|
23 | 23 | _coerce_indexer_dtype)
|
24 | 24 | from pandas.types.api import CategoricalDtype
|
@@ -1897,59 +1897,3 @@ def _convert_to_list_like(list_like):
|
1897 | 1897 | else:
|
1898 | 1898 | # is this reached?
|
1899 | 1899 | return [list_like]
|
1900 |
| - |
1901 |
| - |
1902 |
| -def _concat_compat(to_concat, axis=0): |
1903 |
| - """Concatenate an object/categorical array of arrays, each of which is a |
1904 |
| - single dtype |
1905 |
| -
|
1906 |
| - Parameters |
1907 |
| - ---------- |
1908 |
| - to_concat : array of arrays |
1909 |
| - axis : int |
1910 |
| - Axis to provide concatenation in the current implementation this is |
1911 |
| - always 0, e.g. we only have 1D categoricals |
1912 |
| -
|
1913 |
| - Returns |
1914 |
| - ------- |
1915 |
| - Categorical |
1916 |
| - A single array, preserving the combined dtypes |
1917 |
| - """ |
1918 |
| - |
1919 |
| - def convert_categorical(x): |
1920 |
| - # coerce to object dtype |
1921 |
| - if is_categorical_dtype(x.dtype): |
1922 |
| - return x.get_values() |
1923 |
| - return x.ravel() |
1924 |
| - |
1925 |
| - if get_dtype_kinds(to_concat) - set(['object', 'category']): |
1926 |
| - # convert to object type and perform a regular concat |
1927 |
| - from pandas.core.common import _concat_compat |
1928 |
| - return _concat_compat([np.array(x, copy=False, dtype=object) |
1929 |
| - for x in to_concat], axis=0) |
1930 |
| - |
1931 |
| - # we could have object blocks and categoricals here |
1932 |
| - # if we only have a single categoricals then combine everything |
1933 |
| - # else its a non-compat categorical |
1934 |
| - categoricals = [x for x in to_concat if is_categorical_dtype(x.dtype)] |
1935 |
| - |
1936 |
| - # validate the categories |
1937 |
| - categories = categoricals[0] |
1938 |
| - rawcats = categories.categories |
1939 |
| - for x in categoricals[1:]: |
1940 |
| - if not categories.is_dtype_equal(x): |
1941 |
| - raise ValueError("incompatible categories in categorical concat") |
1942 |
| - |
1943 |
| - # we've already checked that all categoricals are the same, so if their |
1944 |
| - # length is equal to the input then we have all the same categories |
1945 |
| - if len(categoricals) == len(to_concat): |
1946 |
| - # concating numeric types is much faster than concating object types |
1947 |
| - # and fastpath takes a shorter path through the constructor |
1948 |
| - return Categorical(np.concatenate([x.codes for x in to_concat], |
1949 |
| - axis=0), |
1950 |
| - rawcats, ordered=categoricals[0].ordered, |
1951 |
| - fastpath=True) |
1952 |
| - else: |
1953 |
| - concatted = np.concatenate(list(map(convert_categorical, to_concat)), |
1954 |
| - axis=0) |
1955 |
| - return Categorical(concatted, rawcats) |
0 commit comments