File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -270,7 +270,7 @@ def _get_data_buffer(
270270 buffer = PandasBuffer (self ._col .to_numpy (), allow_copy = self ._allow_copy )
271271 dtype = self .dtype
272272 elif self .dtype [0 ] == DtypeKind .CATEGORICAL :
273- codes = self ._col .values .codes
273+ codes = self ._col .values ._codes
274274 buffer = PandasBuffer (codes , allow_copy = self ._allow_copy )
275275 dtype = self ._dtype_from_pandasdtype (codes .dtype )
276276 elif self .dtype [0 ] == DtypeKind .STRING :
Original file line number Diff line number Diff line change 55import pytest
66
77from pandas ._libs .tslibs import iNaT
8+ import pandas .util ._test_decorators as td
89
910import pandas as pd
1011import pandas ._testing as tm
@@ -193,3 +194,13 @@ def test_datetime():
193194 assert col .describe_null == (ColumnNullType .USE_SENTINEL , iNaT )
194195
195196 tm .assert_frame_equal (df , from_dataframe (df .__dataframe__ ()))
197+
198+
199+ @td .skip_if_np_lt ("1.23" )
200+ def test_categorical_to_numpy_dlpack ():
201+ # https://github.com/pandas-dev/pandas/issues/48393
202+ df = pd .DataFrame ({"A" : pd .Categorical (["a" , "b" , "a" ])})
203+ col = df .__dataframe__ ().get_column_by_name ("A" )
204+ result = np .from_dlpack (col .get_buffers ()["data" ][0 ])
205+ expected = np .array ([0 , 1 , 0 ], dtype = "int8" )
206+ tm .assert_numpy_array_equal (result , expected )
You can’t perform that action at this time.
0 commit comments