-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
SparseArray is an ExtensionArray #22325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ee187eb
32c1372
b265659
8dfc898
9c57725
13952ab
7a6e7fa
1016af1
072abec
0ad61cc
5b0b524
224744a
620b5fb
164c401
65f83d6
0b3c682
69a5d13
f2b5862
fa80fc5
3f20890
484adb0
1df1190
4246ac4
a849699
c4da319
a2f158f
26b671a
375e160
0a37050
3c2cb0f
27c6378
e52dae9
b6d8430
640c4a5
6b61597
427234f
e055629
a79359c
de3aa71
21f4ee3
c1e594a
dc7f93f
eb09d21
7dcf4b2
b39658a
a8b76bd
e041313
595535e
7700299
f1ff7da
33fa6f7
40c035e
1d49cc7
6f4b6b6
6f037b5
7da220e
bfbe4ab
c5666b6
ff6037c
5c362ef
55cac36
c4e8784
a00f987
a6d7eac
4b4f9bd
82801be
1a149dc
fde19d7
a7ba8f6
5064217
e31e8aa
79c8e9c
26993fe
6eeec11
50de326
5ef1747
f31970c
f1b860f
5c44275
33bc8f8
9bf13ad
de1fb5b
da580cd
88b73c3
afde64d
e603d3d
ec5eb9a
a72ee1a
f147635
c35c7c2
e159ef2
d48a8fa
3bcf57e
31d401f
a4369c2
608b499
14e60c9
550f163
821cc91
e21ed21
aeb8c8c
34c90ed
2103959
26af959
e5920c2
084a967
bb17760
dde7852
f1b4e6b
6a31077
02aa7f7
3a7ee2d
d6fe191
b1ea874
2213b83
94664c4
e54160c
04a2dbb
fb01d1a
f78ae81
11d5b40
ba70753
82bab3c
2990124
a9d0f17
0c52c37
998f113
38b0356
7206d94
fe771b5
12e424c
3bd567f
f816346
1a1dcf4
e3d9173
2715cdb
4e40599
0aa3934
a3becb6
5660b9a
dd3cba5
cc65b8a
06dce5f
f7351d3
2055494
f310322
0008164
027f6d8
c0d9875
44b218c
47fa73a
c2c489f
3729927
9ba49e1
543ac7c
f66ef6f
ba8fc9d
9185e33
11799ab
73e7626
ebece16
7db6990
be21f42
e857363
d0ee038
54f4417
2082d86
f846606
ce8e0ac
1f6590e
b758469
f6b0924
232518c
e8b37da
0197e0c
62326ae
f008c38
88c6126
5c8662e
78798cf
b051424
78979b6
2333db1
b41d473
d6a2479
a23c27c
7372eb3
cab8c54
52ae275
9c9b49e
f5d7492
b4b4cbc
bf98b9d
f3d2681
7d4d3ba
57c03c2
0dbc33e
c217cf5
2ea7a91
8f2f228
c83bed7
53e494e
627b9ce
df0293a
a590418
7821f19
ee26c52
40390f1
15a164d
88432c8
3e7ec90
7b0a179
20d8815
3e81c69
1098a7a
10d204a
69075d8
0764baa
a4a47c5
a5b6c39
70d8268
7aed79f
11e55aa
11606af
2f73179
1b3058a
f4ec928
8c67ca2
cc89ec7
3f713d4
886fe03
75099af
731fc06
f91141d
37a4b57
4aad8e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,7 @@ def _wrap_result(name, data, sparse_index, fill_value, dtype=None): | |
|
||
|
||
class SparseArray(PandasObject, ExtensionArray): | ||
|
||
def __init__(self, data, sp_index=None, fill_value=np.nan, kind='block'): | ||
|
||
if sp_index is None: | ||
|
@@ -148,7 +149,7 @@ def __init__(self, data, sp_index=None, fill_value=np.nan, kind='block'): | |
self.fill_value = fill_value | ||
|
||
@classmethod | ||
def _from_sequence(cls, scalars, copy=False): | ||
def _from_sequence(cls, scalars, dtype=None, copy=False): | ||
return cls(scalars) | ||
|
||
@classmethod | ||
|
@@ -248,9 +249,11 @@ def take(self, indices, allow_fill=False, fill_value=None): | |
indices = np.asarray(indices, dtype=np.int32) | ||
|
||
if allow_fill: | ||
return self._take_with_fill(indices, fill_value=fill_value) | ||
result = self._take_with_fill(indices, fill_value=fill_value) | ||
else: | ||
return self._take_without_fill(indices) | ||
result = self._take_without_fill(indices) | ||
|
||
return type(self)(result, fill_value=self.fill_value) | ||
|
||
def _take_with_fill(self, indices, fill_value=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason that the take code here is that much expanded compared to before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think take was the first thing I wrote back in June or July, so my memory is fuzzy ;) If I had to guess, I would say additional edge-case handling, but I haven't looked closely either. |
||
if fill_value is None: | ||
|
@@ -271,12 +274,12 @@ def _take_with_fill(self, indices, fill_value=None): | |
else: | ||
raise IndexError('cannot do a non-empty take from an empty axes.') | ||
|
||
# TODO: bounds check | ||
sp_indexer = self.sp_index.lookup_array(indices) | ||
fillable = (indices < 0) | (sp_indexer < 0) | ||
|
||
taken = self.sp_values.take(sp_indexer) | ||
taken[fillable] = fill_value | ||
# Have to fill in two steps, since the user-passed fill value may be | ||
# different from self.fill_value. | ||
taken[sp_indexer < 0] = self.fill_value | ||
taken[indices < 0] = fill_value | ||
return taken | ||
|
||
def _take_without_fill(self, indices): | ||
|
Uh oh!
There was an error while loading. Please reload this page.