File tree 2 files changed +12
-1
lines changed
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(
270
270
buffer = PandasBuffer (self ._col .to_numpy (), allow_copy = self ._allow_copy )
271
271
dtype = self .dtype
272
272
elif self .dtype [0 ] == DtypeKind .CATEGORICAL :
273
- codes = self ._col .values .codes
273
+ codes = self ._col .values ._codes
274
274
buffer = PandasBuffer (codes , allow_copy = self ._allow_copy )
275
275
dtype = self ._dtype_from_pandasdtype (codes .dtype )
276
276
elif self .dtype [0 ] == DtypeKind .STRING :
Original file line number Diff line number Diff line change 5
5
import pytest
6
6
7
7
from pandas ._libs .tslibs import iNaT
8
+ import pandas .util ._test_decorators as td
8
9
9
10
import pandas as pd
10
11
import pandas ._testing as tm
@@ -193,3 +194,13 @@ def test_datetime():
193
194
assert col .describe_null == (ColumnNullType .USE_SENTINEL , iNaT )
194
195
195
196
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