Skip to content

Commit 280b622

Browse files
ctruedenclaude
andcommitted
Fix pandas API usages
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 11deca3 commit 280b622

File tree

3 files changed

+57
-37
lines changed

3 files changed

+57
-37
lines changed

src/scyjava/_convert.py

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -237,72 +237,90 @@ def _stock_java_converters() -> List[Converter]:
237237
),
238238
Converter(
239239
name="int -> java.lang.Byte",
240-
predicate=lambda obj, **hints: isinstance(obj, int)
241-
and ("type" in hints and hints["type"] in ("b", "byte", "Byte"))
242-
and _jc.Byte.MIN_VALUE <= obj <= _jc.Byte.MAX_VALUE,
240+
predicate=lambda obj, **hints: (
241+
isinstance(obj, int)
242+
and ("type" in hints and hints["type"] in ("b", "byte", "Byte"))
243+
and _jc.Byte.MIN_VALUE <= obj <= _jc.Byte.MAX_VALUE
244+
),
243245
converter=_jc.Byte,
244246
priority=Priority.HIGH,
245247
),
246248
Converter(
247249
name="int -> java.lang.Short",
248-
predicate=lambda obj, **hints: isinstance(obj, int)
249-
and ("type" in hints and hints["type"] in ("s", "short", "Short"))
250-
and _jc.Short.MIN_VALUE <= obj <= _jc.Short.MAX_VALUE,
250+
predicate=lambda obj, **hints: (
251+
isinstance(obj, int)
252+
and ("type" in hints and hints["type"] in ("s", "short", "Short"))
253+
and _jc.Short.MIN_VALUE <= obj <= _jc.Short.MAX_VALUE
254+
),
251255
converter=_jc.Short,
252256
priority=Priority.HIGH,
253257
),
254258
Converter(
255259
name="int -> java.lang.Integer",
256-
predicate=lambda obj, **hints: isinstance(obj, int)
257-
and ("type" not in hints or hints["type"] in ("i", "int", "Integer"))
258-
and _jc.Integer.MIN_VALUE <= obj <= _jc.Integer.MAX_VALUE,
260+
predicate=lambda obj, **hints: (
261+
isinstance(obj, int)
262+
and ("type" not in hints or hints["type"] in ("i", "int", "Integer"))
263+
and _jc.Integer.MIN_VALUE <= obj <= _jc.Integer.MAX_VALUE
264+
),
259265
converter=_jc.Integer,
260266
),
261267
Converter(
262268
name="int -> java.lang.Long",
263-
predicate=lambda obj, **hints: isinstance(obj, int)
264-
and ("type" not in hints or hints["type"] in ("j", "l", "long", "Long"))
265-
and _jc.Long.MIN_VALUE <= obj <= _jc.Long.MAX_VALUE,
269+
predicate=lambda obj, **hints: (
270+
isinstance(obj, int)
271+
and ("type" not in hints or hints["type"] in ("j", "l", "long", "Long"))
272+
and _jc.Long.MIN_VALUE <= obj <= _jc.Long.MAX_VALUE
273+
),
266274
converter=_jc.Long,
267275
priority=Priority.NORMAL - 1,
268276
),
269277
Converter(
270278
name="int -> java.math.BigInteger",
271-
predicate=lambda obj, **hints: isinstance(obj, int)
272-
and (
273-
"type" not in hints or hints["type"] in ("bi", "bigint", "BigInteger")
279+
predicate=lambda obj, **hints: (
280+
isinstance(obj, int)
281+
and (
282+
"type" not in hints
283+
or hints["type"] in ("bi", "bigint", "BigInteger")
284+
)
274285
),
275286
converter=lambda obj: _jc.BigInteger(str(obj)),
276287
priority=Priority.NORMAL - 2,
277288
),
278289
Converter(
279290
name="float -> java.lang.Float",
280-
predicate=lambda obj, **hints: isinstance(obj, float)
281-
and ("type" not in hints or hints["type"] in ("f", "float", "Float"))
282-
and (
283-
math.isinf(obj)
284-
or math.isnan(obj)
285-
or -_jc.Float.MAX_VALUE <= obj <= _jc.Float.MAX_VALUE
291+
predicate=lambda obj, **hints: (
292+
isinstance(obj, float)
293+
and ("type" not in hints or hints["type"] in ("f", "float", "Float"))
294+
and (
295+
math.isinf(obj)
296+
or math.isnan(obj)
297+
or -_jc.Float.MAX_VALUE <= obj <= _jc.Float.MAX_VALUE
298+
)
286299
),
287300
converter=_jc.Float,
288301
),
289302
Converter(
290303
name="float -> java.lang.Double",
291-
predicate=lambda obj, **hints: isinstance(obj, float)
292-
and ("type" not in hints or hints["type"] in ("d", "double", "Double"))
293-
and (
294-
math.isinf(obj)
295-
or math.isnan(obj)
296-
or -_jc.Double.MAX_VALUE <= obj <= _jc.Double.MAX_VALUE
304+
predicate=lambda obj, **hints: (
305+
isinstance(obj, float)
306+
and ("type" not in hints or hints["type"] in ("d", "double", "Double"))
307+
and (
308+
math.isinf(obj)
309+
or math.isnan(obj)
310+
or -_jc.Double.MAX_VALUE <= obj <= _jc.Double.MAX_VALUE
311+
)
297312
),
298313
converter=_jc.Double,
299314
priority=Priority.NORMAL - 1,
300315
),
301316
Converter(
302317
name="float -> java.math.BigDecimal",
303-
predicate=lambda obj, **hints: isinstance(obj, float)
304-
and (
305-
"type" not in hints or hints["type"] in ("bd", "bigdec", "BigDecimal")
318+
predicate=lambda obj, **hints: (
319+
isinstance(obj, float)
320+
and (
321+
"type" not in hints
322+
or hints["type"] in ("bd", "bigdec", "BigDecimal")
323+
)
306324
),
307325
converter=lambda obj: _jc.BigDecimal(str(obj)),
308326
priority=Priority.NORMAL - 2,

tests/test_introspect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def test_jreflect_ctors(self):
5353
arraylist_Obj = scyjava.jreflect(ArrayList, "constructors")
5454
assert len(str_Obj) == len(arraylist_Obj) == 3
5555
arraylist_Obj.sort(
56-
key=lambda row: f"{row['type']}:{row['name']}:{','.join(str(row['arguments']))}"
56+
key=lambda row: (
57+
f"{row['type']}:{row['name']}:{','.join(str(row['arguments']))}"
58+
)
5759
)
5860
assert arraylist_Obj == [
5961
{

tests/test_pandas.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ def testPandasToTable(self):
6060
df = pd.DataFrame(array, columns=columns)
6161

6262
# Convert column 0 to integer
63-
df.iloc[:, 0] = (df.iloc[:, 0] * 100).astype("int")
63+
df[columns[0]] = (df[columns[0]] * 100).astype("int")
6464
# Convert column 1 to bool
65-
df.iloc[:, 1] = df.iloc[:, 1] > 0.5
65+
df[columns[1]] = df[columns[1]] > 0.5
6666
# Convert column 2 to string
67-
df.iloc[:, 2] = df.iloc[:, 2].to_string(index=False).split("\n")
67+
df[columns[2]] = df[columns[2]].to_string(index=False).split("\n")
6868

6969
table = to_java(df)
7070

@@ -137,11 +137,11 @@ def testTabletoPandas(self):
137137

138138
# fill mixed table
139139
for i in range(table.getRowCount()):
140-
table.set(0, i, Float(float(array_float[i])))
140+
table.set(0, i, Float(float(array_float[i].item())))
141141
table.set(1, i, Integer(int(array_int[i].item())))
142-
table.set(2, i, Boolean(bool(array_bool[i])))
142+
table.set(2, i, Boolean(bool(array_bool[i].item())))
143143
table.set(3, i, String(array_str[i]))
144-
table.set(4, i, Double(float(array_double[i])))
144+
table.set(4, i, Double(float(array_double[i].item())))
145145

146146
df = to_python(table)
147147
# Table types cannot be the same here, unless we want to cast.

0 commit comments

Comments
 (0)