File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,13 @@ def pandas_to_array(data):
86
86
if hasattr (data , "to_numpy" ) and hasattr (data , "isnull" ):
87
87
# typically, but not limited to pandas objects
88
88
vals = data .to_numpy ()
89
- mask = data .isnull ().to_numpy ()
89
+ null_data = data .isnull ()
90
+ if hasattr (null_data , "to_numpy" ):
91
+ # pandas Series
92
+ mask = null_data .to_numpy ()
93
+ else :
94
+ # pandas Index
95
+ mask = null_data
90
96
if mask .any ():
91
97
# there are missing values
92
98
ret = np .ma .MaskedArray (vals , mask )
Original file line number Diff line number Diff line change @@ -430,6 +430,13 @@ def test_pandas_to_array(input_dtype):
430
430
assert isinstance (wrapped , TensorVariable )
431
431
432
432
433
+ def test_pandas_to_array_pandas_index ():
434
+ data = pd .Index ([1 , 2 , 3 ])
435
+ result = pandas_to_array (data )
436
+ expected = np .array ([1 , 2 , 3 ])
437
+ np .testing .assert_array_equal (result , expected )
438
+
439
+
433
440
def test_walk_model ():
434
441
d = at .vector ("d" )
435
442
b = at .vector ("b" )
You can’t perform that action at this time.
0 commit comments