Skip to content

Commit 5aebc2d

Browse files
committed
[GR-17146] [GR-17394] [GR-17439] [GH-65] Support Pandas version 0.25.0.
PullRequest: graalpython/598
2 parents 9dabfe6 + 1ab637d commit 5aebc2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1960
-252
lines changed

graalpython/com.oracle.graal.python.cext/src/abstract.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -331,11 +331,7 @@ PyObject * PySequence_Fast(PyObject *v, const char *m) {
331331
return v;
332332
}
333333

334-
PyObject* result = UPCALL_CEXT_O(_jls_PySequence_List, native_to_java(v));
335-
if (result == NULL) {
336-
PyErr_SetString(PyExc_TypeError, m);
337-
}
338-
return result;
334+
return UPCALL_CEXT_O(_jls_PySequence_List, native_to_java(v));
339335
}
340336

341337
UPCALL_ID(PyObject_GetItem);
@@ -348,6 +344,11 @@ PyObject * PyMapping_Keys(PyObject *o) {
348344
return UPCALL_CEXT_O(_jls_PyMapping_Keys, native_to_java(o));
349345
}
350346

347+
// taken from CPython "Objects/abstract.c"
348+
int PyMapping_Check(PyObject *o) {
349+
return o && o->ob_type->tp_as_mapping && o->ob_type->tp_as_mapping->mp_subscript;
350+
}
351+
351352
// taken from CPython "Objects/abstract.c"
352353
int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
353354
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ allocfunc get_tp_alloc(PyTypeObject* obj) {
312312
return obj->tp_alloc;
313313
}
314314

315+
/** to be used from Java code only; reads native 'tp_flags' field */
316+
unsigned long get_tp_flags(PyTypeObject* obj) {
317+
return obj->tp_flags;
318+
}
319+
315320
/** to be used from Java code only; returns the type ID for a byte array */
316321
polyglot_typeid get_byte_array_typeid(uint64_t len) {
317322
return polyglot_array_typeid(polyglot_i8_typeid(), len);

graalpython/com.oracle.graal.python.cext/src/unicodeobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,8 @@ int PyUnicode_Compare(PyObject *left, PyObject *right) {
387387
int _PyUnicode_EqualToASCIIString( PyObject *left, const char *right) {
388388
return UPCALL_CEXT_I(_jls_PyUnicode_Compare, native_to_java(left), polyglot_from_string(right, SRC_CS)) == 0;
389389
}
390+
391+
UPCALL_ID(PyUnicode_AsUnicodeEscapeString);
392+
PyObject * PyUnicode_AsUnicodeEscapeString(PyObject *unicode) {
393+
return UPCALL_CEXT_O(_jls_PyUnicode_AsUnicodeEscapeString, native_to_java(unicode));
394+
}

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_abstract.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,3 +789,21 @@ def compile_module(self, name):
789789
arguments=["PyObject* obj"],
790790
cmpfunc=unhandled_error_compare
791791
)
792+
793+
test_PyMapping_Check = CPyExtFunction(
794+
lambda args: 1 if isinstance(args[0], (dict, str, tuple, list)) else 0,
795+
lambda: (
796+
(dict(), ),
797+
("not a number", ),
798+
({}, ),
799+
({"a": "yes"}, ),
800+
(tuple(), ),
801+
(list(), ),
802+
(1, ),
803+
(None, ),
804+
),
805+
resultspec="i",
806+
argspec='O',
807+
arguments=["PyObject* obj"],
808+
cmpfunc=unhandled_error_compare
809+
)

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_unicode.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -70,6 +70,11 @@ def _reference_findchar(args):
7070
return string.rfind(char, start, end)
7171

7272

73+
def _reference_unicode_escape(args):
74+
import _codecs
75+
return _codecs.unicode_escape_encode(args[0])[0]
76+
77+
7378
class CustomString(str):
7479
pass
7580

@@ -464,3 +469,15 @@ def compile_module(self, name):
464469
arguments=["PyObject* str", "PyObject* seq"],
465470
cmpfunc=unhandled_error_compare
466471
)
472+
473+
test_PyUnicode_AsUnicodeEscapeString = CPyExtFunction(
474+
_reference_unicode_escape,
475+
lambda: (
476+
("abcd", ),
477+
("öüä", ),
478+
),
479+
resultspec="O",
480+
argspec='O',
481+
arguments=["PyObject* str"],
482+
cmpfunc=unhandled_error_compare
483+
)

graalpython/com.oracle.graal.python.test/src/tests/test_float.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ def test_hex(self):
127127
f = float(input)
128128
self.assertEqual(toHex(f), expected);
129129

130+
def test_nan(self):
131+
self.assertNotEqual(NAN, NAN)
132+
self.assertNotEqual(float('nan'), float('nan'))
133+
self.assertTrue(NAN is NAN)
134+
130135

131136
fromHex = float.fromhex
132137

graalpython/com.oracle.graal.python.test/src/tests/test_int.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,38 @@ def __int__(self):
336336
assert int(SpecInt0()) == 0
337337

338338
def test_create_int_from_string():
339-
assert int("5c7920a80f5261a2e5322163c79b71a25a41f414", 16) == 527928385865769069253929759180846776123316630548
339+
assert int("5c7920a80f5261a2e5322163c79b71a25a41f414", 16) == 527928385865769069253929759180846776123316630548
340+
class IndexLike:
341+
def __index__(self):
342+
return 16
343+
assert int("123ff", IndexLike()) == 0x123ff
344+
try:
345+
int("123ff", None)
346+
except TypeError:
347+
assert True
348+
else:
349+
assert False, "expected TypeError"
350+
351+
352+
def test_create_int_from_float():
353+
assert int(123.0) == 123
354+
assert int(123.4) == 123
355+
try:
356+
int(float('nan'))
357+
except ValueError:
358+
assert True
359+
else:
360+
assert False, "expected ValueError"
361+
362+
class FloatSub(float):
363+
pass
364+
365+
try:
366+
int(FloatSub(float('nan')))
367+
except ValueError:
368+
assert True
369+
else:
370+
assert False, "expected ValueError"
340371

341372

342373
class FromBytesTests(unittest.TestCase):

graalpython/com.oracle.graal.python.test/src/tests/test_list.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ def test_set_slice(self):
372372
self.assertEqual([1, 2, 3, 4], a)
373373
else:
374374
assert False, "expected ValueError"
375+
376+
a = [1, 2, 3, 4]
377+
a[:] = map(next, [iter([None,]), iter([None,])])
378+
self.assertEqual([None, None], a)
375379

376380

377381
def test_set_slice_class_iter(self):

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.oracle.graal.python.builtins.modules.ImpModuleBuiltins;
6464
import com.oracle.graal.python.builtins.modules.ItertoolsModuleBuiltins;
6565
import com.oracle.graal.python.builtins.modules.JavaModuleBuiltins;
66+
import com.oracle.graal.python.builtins.modules.LZMAModuleBuiltins;
6667
import com.oracle.graal.python.builtins.modules.LocaleModuleBuiltins;
6768
import com.oracle.graal.python.builtins.modules.MMapModuleBuiltins;
6869
import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins;
@@ -109,6 +110,7 @@
109110
import com.oracle.graal.python.builtins.objects.exception.BaseExceptionBuiltins;
110111
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
111112
import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins;
113+
import com.oracle.graal.python.builtins.objects.floats.PFloat;
112114
import com.oracle.graal.python.builtins.objects.foreign.ForeignObjectBuiltins;
113115
import com.oracle.graal.python.builtins.objects.frame.FrameBuiltins;
114116
import com.oracle.graal.python.builtins.objects.function.AbstractFunctionBuiltins;
@@ -125,6 +127,8 @@
125127
import com.oracle.graal.python.builtins.objects.iterator.PZipBuiltins;
126128
import com.oracle.graal.python.builtins.objects.iterator.SentinelIteratorBuiltins;
127129
import com.oracle.graal.python.builtins.objects.list.ListBuiltins;
130+
import com.oracle.graal.python.builtins.objects.lzma.LZMACompressorBuiltins;
131+
import com.oracle.graal.python.builtins.objects.lzma.LZMADecompressorBuiltins;
128132
import com.oracle.graal.python.builtins.objects.mappingproxy.MappingproxyBuiltins;
129133
import com.oracle.graal.python.builtins.objects.memoryview.BufferBuiltins;
130134
import com.oracle.graal.python.builtins.objects.memoryview.MemoryviewBuiltins;
@@ -235,7 +239,8 @@ private static final String[] initializeCoreFiles() {
235239
"pyio_patches",
236240
"pwd",
237241
"resource",
238-
"_contextvars"));
242+
"_contextvars",
243+
"_lzma"));
239244
// must be last
240245
coreFiles.add("final_patches");
241246
return coreFiles.toArray(new String[coreFiles.size()]);
@@ -351,7 +356,10 @@ private static final PythonBuiltins[] initializeBuiltins() {
351356
new RLockBuiltins(),
352357
new PwdModuleBuiltins(),
353358
new ResourceModuleBuiltins(),
354-
new ContextvarsModuleBuiltins()));
359+
new ContextvarsModuleBuiltins(),
360+
new LZMAModuleBuiltins(),
361+
new LZMACompressorBuiltins(),
362+
new LZMADecompressorBuiltins()));
355363
if (!TruffleOptions.AOT) {
356364
ServiceLoader<PythonBuiltins> providers = ServiceLoader.load(PythonBuiltins.class, Python3Core.class.getClassLoader());
357365
for (PythonBuiltins builtin : providers) {
@@ -369,6 +377,7 @@ private static final PythonBuiltins[] initializeBuiltins() {
369377

370378
@CompilationFinal private PInt pyTrue;
371379
@CompilationFinal private PInt pyFalse;
380+
@CompilationFinal private PFloat pyNaN;
372381

373382
private final PythonParser parser;
374383

@@ -521,8 +530,9 @@ private void initializeTypes() {
521530
}
522531
}
523532
// now initialize well-known objects
524-
pyTrue = new PInt(lookupType(PythonBuiltinClassType.Boolean), BigInteger.ONE);
525-
pyFalse = new PInt(lookupType(PythonBuiltinClassType.Boolean), BigInteger.ZERO);
533+
pyTrue = new PInt(PythonBuiltinClassType.Boolean, BigInteger.ONE);
534+
pyFalse = new PInt(PythonBuiltinClassType.Boolean, BigInteger.ZERO);
535+
pyNaN = new PFloat(PythonBuiltinClassType.PFloat, Double.NaN);
526536
}
527537

528538
private void populateBuiltins() {
@@ -638,6 +648,10 @@ public PInt getFalse() {
638648
return pyFalse;
639649
}
640650

651+
public PFloat getNaN() {
652+
return pyNaN;
653+
}
654+
641655
public RuntimeException raiseInvalidSyntax(Source source, SourceSection section, String message, Object... arguments) {
642656
Node location = new Node() {
643657
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public enum PythonBuiltinClassType implements LazyPythonClass {
108108
PClassmethod("classmethod", "builtins"),
109109
PScandirIterator("ScandirIterator", "posix"),
110110
PDirEntry("DirEntry", "posix"),
111+
PLZMACompressor("LZMACompressor", "_lzma"),
112+
PLZMADecompressor("LZMADecompressor", "_lzma"),
111113

112114
// Errors and exceptions:
113115

@@ -152,6 +154,7 @@ public enum PythonBuiltinClassType implements LazyPythonClass {
152154
TimeoutError("TimeoutError", "builtins"),
153155
ZipImportError("ZipImportError", "zipimport"),
154156
ZLibError("error", "zlib"),
157+
LZMAError("LZMAError", "_lzma"),
155158

156159
// todo: all OS errors
157160

@@ -282,6 +285,7 @@ public Shape getInstanceShape() {
282285
TimeoutError.base = OSError;
283286
ZipImportError.base = ImportError;
284287
ZLibError.base = Exception;
288+
LZMAError.base = Exception;
285289

286290
ReferenceError.base = Exception;
287291
RuntimeError.base = Exception;

0 commit comments

Comments
 (0)