|
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
|
@@ -1873,59 +1873,3 @@ def _convert_to_list_like(list_like):
|
1873 | 1873 | else:
|
1874 | 1874 | # is this reached?
|
1875 | 1875 | return [list_like]
|
1876 |
| - |
1877 |
| - |
1878 |
| -def _concat_compat(to_concat, axis=0): |
1879 |
| - """Concatenate an object/categorical array of arrays, each of which is a |
1880 |
| - single dtype |
1881 |
| -
|
1882 |
| - Parameters |
1883 |
| - ---------- |
1884 |
| - to_concat : array of arrays |
1885 |
| - axis : int |
1886 |
| - Axis to provide concatenation in the current implementation this is |
1887 |
| - always 0, e.g. we only have 1D categoricals |
1888 |
| -
|
1889 |
| - Returns |
1890 |
| - ------- |
1891 |
| - Categorical |
1892 |
| - A single array, preserving the combined dtypes |
1893 |
| - """ |
1894 |
| - |
1895 |
| - def convert_categorical(x): |
1896 |
| - # coerce to object dtype |
1897 |
| - if is_categorical_dtype(x.dtype): |
1898 |
| - return x.get_values() |
1899 |
| - return x.ravel() |
1900 |
| - |
1901 |
| - if get_dtype_kinds(to_concat) - set(['object', 'category']): |
1902 |
| - # convert to object type and perform a regular concat |
1903 |
| - from pandas.core.common import _concat_compat |
1904 |
| - return _concat_compat([np.array(x, copy=False, dtype=object) |
1905 |
| - for x in to_concat], axis=0) |
1906 |
| - |
1907 |
| - # we could have object blocks and categoricals here |
1908 |
| - # if we only have a single categoricals then combine everything |
1909 |
| - # else its a non-compat categorical |
1910 |
| - categoricals = [x for x in to_concat if is_categorical_dtype(x.dtype)] |
1911 |
| - |
1912 |
| - # validate the categories |
1913 |
| - categories = categoricals[0] |
1914 |
| - rawcats = categories.categories |
1915 |
| - for x in categoricals[1:]: |
1916 |
| - if not categories.is_dtype_equal(x): |
1917 |
| - raise ValueError("incompatible categories in categorical concat") |
1918 |
| - |
1919 |
| - # we've already checked that all categoricals are the same, so if their |
1920 |
| - # length is equal to the input then we have all the same categories |
1921 |
| - if len(categoricals) == len(to_concat): |
1922 |
| - # concating numeric types is much faster than concating object types |
1923 |
| - # and fastpath takes a shorter path through the constructor |
1924 |
| - return Categorical(np.concatenate([x.codes for x in to_concat], |
1925 |
| - axis=0), |
1926 |
| - rawcats, ordered=categoricals[0].ordered, |
1927 |
| - fastpath=True) |
1928 |
| - else: |
1929 |
| - concatted = np.concatenate(list(map(convert_categorical, to_concat)), |
1930 |
| - axis=0) |
1931 |
| - return Categorical(concatted, rawcats) |
0 commit comments