Skip to content

Commit 2fca2ce

Browse files
merge master
1 parent de3a85c commit 2fca2ce

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ Performance Improvements
252252
Bug Fixes
253253
~~~~~~~~~
254254

255-
256255
Categorical
257256
^^^^^^^^^^^
258257

@@ -391,7 +390,7 @@ Sparse
391390

392391
- Significant speedup in `SparseArray` initialization that benefits most operations, fixing performance regression introduced in v0.20.0 (:issue:`24985`)
393392
- Bug in :class:`SparseFrame` constructor where passing ``None`` as the data would cause ``default_fill_value`` to be ignored (:issue:`16807`)
394-
-
393+
- Bug in `SparseDataFrame` when adding a column in which the length of values does not match length of index, ``AssertionError`` is raised instead of raising ``ValueError`` (:issue:`25484`)
395394

396395

397396
Other

pandas/core/sparse/frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ def sp_maker(x, index=None):
430430

431431
elif isinstance(value, SparseArray):
432432
if len(value) != len(self.index):
433-
raise AssertionError('Length of values does not match '
434-
'length of index')
433+
raise ValueError('Length of values does not match '
434+
'length of index')
435435
clean = value
436436

437437
elif hasattr(value, '__iter__'):
@@ -441,8 +441,8 @@ def sp_maker(x, index=None):
441441
clean = sp_maker(clean)
442442
else:
443443
if len(value) != len(self.index):
444-
raise AssertionError('Length of values does not match '
445-
'length of index')
444+
raise ValueError('Length of values does not match '
445+
'length of index')
446446
clean = sp_maker(value)
447447

448448
# Scalar

pandas/tests/sparse/frame/test_frame.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,9 @@ def _check_frame(frame, orig):
568568
assert len(frame['I'].sp_values) == N // 2
569569

570570
# insert ndarray wrong size
571-
msg = "Length of values does not match length of index"
572-
with pytest.raises(AssertionError, match=msg):
571+
# GH 25484
572+
msg = 'Length of values does not match length of index'
573+
with pytest.raises(ValueError, match=msg):
573574
frame['foo'] = np.random.randn(N - 1)
574575

575576
# scalar value

0 commit comments

Comments
 (0)