scatter3d-anywidget 0.1.10__py3-none-any.whl → 0.1.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
scatter3d/scatter3d.py CHANGED
@@ -158,10 +158,51 @@ class Category:
158
158
  return label_coding
159
159
 
160
160
  def _encode_values(self, values):
161
- coded_values = values.replace_strict(
162
- self._label_coding, default=0, return_dtype=narwhals.UInt16
163
- ).to_numpy()
164
- self._coded_values = coded_values
161
+ mapping = self._label_coding
162
+ if mapping is None:
163
+ raise RuntimeError("label coding should be set, but it is not")
164
+
165
+ # Fast-path: no labels => everything is "unassigned" (0).
166
+ # Also avoids Narwhals 2.6.0 pandas replace_strict merge bugs with empty mapping.
167
+ if len(mapping) == 0:
168
+ # preserve length
169
+ n = int(values.len()) if hasattr(values, "len") else len(values.to_native())
170
+ self._coded_values = numpy.zeros(n, dtype=numpy.uint16)
171
+ return
172
+
173
+ # Narwhals 2.6.0 + pandas backend: replace_strict breaks if series.name is None
174
+ if values.name is None:
175
+ tmp_name = "__scatter3d_tmp_category__"
176
+ if values.implementation == narwhals.Implementation.PANDAS:
177
+ native = values.to_native()
178
+ # native is a pandas.Series
179
+ native = native.rename(tmp_name)
180
+ values = narwhals.from_native(native, series_only=True)
181
+ else:
182
+ # rebuild as a named Narwhals series for other backends
183
+ # (to_native may return a backend-native Series; name handling varies)
184
+ arr = values.to_numpy()
185
+ values = narwhals.new_series(
186
+ name=tmp_name, values=arr, backend=values.implementation
187
+ )
188
+
189
+ try:
190
+ # Newer Narwhals path
191
+ coded = values.replace_strict(
192
+ mapping, default=0, return_dtype=narwhals.UInt16
193
+ )
194
+ self._coded_values = coded.to_numpy()
195
+ return
196
+ except TypeError as e:
197
+ if "default" not in str(e):
198
+ raise
199
+
200
+ # Narwhals 2.6.0 path: no default; fill nulls after strict replace
201
+ coded = values.replace_strict(mapping, return_dtype=narwhals.UInt16)
202
+
203
+ # fill_null exists on many backends; if it doesn't, fall back to numpy fill
204
+ coded = coded.fill_null(0)
205
+ self._coded_values = coded.to_numpy()
165
206
 
166
207
  @property
167
208
  def values(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: scatter3d-anywidget
3
- Version: 0.1.10
3
+ Version: 0.1.12
4
4
  Summary: 3D scatter widget with lasso selection
5
5
  License: MIT
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -10,8 +10,8 @@ Classifier: Programming Language :: Python :: 3.13
10
10
  Classifier: Intended Audience :: Science/Research
11
11
  Classifier: Topic :: Scientific/Engineering :: Visualization
12
12
  Requires-Dist: anywidget>=0.9.21
13
- Requires-Dist: narwhals>=2.6.0
14
- Requires-Dist: numpy>=2.3.5
13
+ Requires-Dist: narwhals==2.6.0
14
+ Requires-Dist: numpy==2.0.2
15
15
  Requires-Python: >=3.12
16
16
  Project-URL: Homepage, https://github.com/JoseBlanca/any_scatter3d
17
17
  Project-URL: Repository, https://github.com/JoseBlanca/any_scatter3d
@@ -1,8 +1,8 @@
1
1
  scatter3d/__init__.py,sha256=nVTx6roiwzTe5lpGoMHw7pDZovHdhbxcVOgg4J3trT4,142
2
- scatter3d/scatter3d.py,sha256=LEtWsWz1oCppcxwimadfbbeFzMsOOSvBd1xD6qXFIh8,38693
2
+ scatter3d/scatter3d.py,sha256=NP-eM6fe0mpbjwG3R7Qjy4oEUd1NywS83V_UKc8HeNQ,40509
3
3
  scatter3d/static/scatter3d.js,sha256=tP5SmjjyUj1Bo7NkA3OfiYG84tgxnikaiamSvp_UXgI,896353
4
4
  scatter3d/static/scatter3d.js.map,sha256=yJjSFS0ynkMyVeuE8RnLj0v5hvAZPWWQ5gAk8Vh6Qe0,3035467
5
5
  scatter3d/widget_test.py,sha256=rnLO13uzSJV3uKwYR_xpp-QECd_hi-LC-Ff2bV0AvZM,1866
6
- scatter3d_anywidget-0.1.10.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
7
- scatter3d_anywidget-0.1.10.dist-info/METADATA,sha256=benI5AQaYMfzKwnAX-FzWPsgawI3CeBVJTYomtKUkV0,4697
8
- scatter3d_anywidget-0.1.10.dist-info/RECORD,,
6
+ scatter3d_anywidget-0.1.12.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
7
+ scatter3d_anywidget-0.1.12.dist-info/METADATA,sha256=K_l99otDBVHXmK0ttpojbmp9b6X77_gKpjvL7e-1Kyc,4697
8
+ scatter3d_anywidget-0.1.12.dist-info/RECORD,,