Skip to content

Commit

Permalink
Ensured compatibility with NumPy 2.0(.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Jun 29, 2024
1 parent dc4f79a commit b7b402e
Show file tree
Hide file tree
Showing 150 changed files with 87 additions and 8 deletions.
10 changes: 10 additions & 0 deletions pmml-python/src/main/java/numpy/random/BitGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ public void __init__(Object[] args){
super.__setstate__(INIT_ATTRIBUTES, args);
}

@Override
public void __setstate__(Object[] args){
super.__setstate__(SETSTATE_ATTRIBUTES, args);
}

private static final String[] INIT_ATTRIBUTES = {
"seed"
};

private static final String[] SETSTATE_ATTRIBUTES = {
"_seed_seq",
"state"
};
}
27 changes: 21 additions & 6 deletions pmml-python/src/main/java/numpy/random/BitGeneratorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,32 @@ private BitGeneratorUtil(){
static
public BitGenerator createBitGenerator(Object[] args){

// Numpy 1.23.4
// NumPy 1.23.4 or NumPy 2.0.0+
if(args.length == 1){
String bitGeneratorName = (String)args[0];

// XXX
BitGenerator bitGenerator = new BitGenerator("numpy.random._" + bitGeneratorName.toLowerCase(), bitGeneratorName);
// NumPy 1.23.4
if(args[0] instanceof String){
String bitGeneratorName = (String)args[0];

return bitGenerator;
// XXX
BitGenerator bitGenerator = new BitGenerator("numpy.random._" + bitGeneratorName.toLowerCase(), bitGeneratorName);

return bitGenerator;
} else

// NumPy 2.0.0+
if(args[0] instanceof BitGenerator){
BitGenerator bitGenerator = (BitGenerator)args[0];

return bitGenerator;
} else

{
throw new PickleException(Arrays.deepToString(args));
}
} else

// Numpy 1.24.1+
// NumPy 1.24.1+
if(args.length == 2){
String bitGeneratorName = (String)args[0];
ClassDictConstructor bitGeneratorCtor = (ClassDictConstructor)args[1];
Expand Down
38 changes: 38 additions & 0 deletions pmml-python/src/main/java/numpy/random/SeedSequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Villu Ruusmann
*
* This file is part of JPMML-Python
*
* JPMML-Python is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JPMML-Python is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with JPMML-Python. If not, see <http://www.gnu.org/licenses/>.
*/
package numpy.random;

import org.jpmml.python.CythonObject;

public class SeedSequence extends CythonObject {

public SeedSequence(String module, String name){
super(module, name);
}

@Override
public void __init__(Object[] args){
// Ignored
}

@Override
public void __setstate__(Object[] args){
// Ignored
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ functools.partial = functools.Partial
joblib.numpy_pickle.NumpyArrayWrapper = joblib.NumpyArrayWrapper
math.(acos|asin|atan|atan2|ceil|copysign|cos|cosh|degrees|exp|expm1|fabs|floor|hypot|isnan|log|log1p|log10|pow|radians|sin|sinh|sqrt|tan|tanh|trunc) = builtins.Function
numpy.(|core.fromnumeric.)clip = numpy.core.Function
numpy.(|core._multiarray_umath.)(absolute|arccos|arcsin|arctan|arctan2|ceil|clip|cos|cosh|degrees|rad2deg|exp|expm1|floor|fmax|fmin|hypot|log|log1p|log10|negative|power|radians|deg2rad|reciprocal|rint|sign|sin|sinh|sqrt|square|tan|tanh) = numpy.core.Function
numpy.(|_core._multiarray_umath.|core._multiarray_umath.)(absolute|arccos|arcsin|arctan|arctan2|ceil|clip|cos|cosh|degrees|rad2deg|exp|expm1|floor|fmax|fmin|hypot|log|log1p|log10|negative|power|radians|deg2rad|reciprocal|rint|sign|sin|sinh|sqrt|square|tan|tanh) = numpy.core.Function
numpy.(bool_|float_|float32|float64|int_|int8|int16|int32|int64|str_|uint8|uint16|uint32|uint64) = builtins.TypeConstructor
numpy.core.(_multiarray_umath|multiarray)._reconstruct = numpy.core.NDArray
numpy.core.(_multiarray_umath|multiarray).scalar = numpy.core.Scalar
numpy.core.numeric._frombuffer = numpy.core.FromBufferConstructor
numpy.(_core|core).numeric._frombuffer = numpy.core.FromBufferConstructor
numpy.core._ufunc_reconstruct = numpy.core.UFunc
numpy.dtype = numpy.DType
numpy.ma.core._mareconstruct = numpy.core.MaskedArray
numpy.random.__RandomState_ctor = numpy.random.RandomState
numpy.random._pickle.__bit_generator_ctor = numpy.random.BitGenerator
numpy.random._pickle.__generator_ctor = numpy.random.Generator
numpy.random._pickle.__randomstate_ctor = numpy.random.LegacyRandomState
numpy.random.bit_generator.__pyx_unpickle_SeedSequence = numpy.random.SeedSequence
pandas.core.arrays.boolean.BooleanArray = pandas.core.MaskedArray
pandas.core.arrays.boolean.BooleanDtype = pandas.core.BooleanDtype
pandas.core.arrays.categorical.Categorical = pandas.core.Categorical
Expand Down
12 changes: 12 additions & 0 deletions pmml-python/src/test/java/org/jpmml/python/DumpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,22 @@ public void python39() throws Exception {
unpickleNumpyArrays("python-3.9_numpy-1.23.4");
unpickleNumpyArrays("python-3.9_numpy-1.24.1");
unpickleNumpyArrays("python-3.9_numpy-1.26.2");
unpickleNumpyArrays("python-3.9_numpy-2.0.0");

unpickleNumpyDtypes("python-3.9_numpy-1.22.3");
unpickleNumpyDtypes("python-3.9_numpy-1.23.4");
unpickleNumpyDtypes("python-3.9_numpy-1.24.1");
unpickleNumpyDtypes("python-3.9_numpy-1.26.2");
unpickleNumpyDtypes("python-3.9_numpy-2.0.0");

unpickleNumpyDatetimeDtypes("python-3.9_numpy-1.24.1");
unpickleNumpyDatetimeDtypes("python-3.9_numpy-1.26.2");
unpickleNumpyDatetimeDtypes("python-3.9_numpy-2.0.0");

unpickleNumpyRNGs("python-3.9_numpy-1.23.4");
unpickleNumpyRNGs("python-3.9_numpy-1.24.1");
unpickleNumpyRNGs("python-3.9_numpy-1.26.2");
unpickleNumpyRNGs("python-3.9_numpy-2.0.0");

unpicklePandasSeries("python-3.9_pandas-1.2.3");
unpicklePandasSeries("python-3.9_pandas-1.3.1");
Expand Down Expand Up @@ -227,17 +231,21 @@ public void python311() throws Exception {
unpickleNumpyArrays("python-3.11_numpy-1.23.4");
unpickleNumpyArrays("python-3.11_numpy-1.24.1");
unpickleNumpyArrays("python-3.11_numpy-1.26.2");
unpickleNumpyArrays("python-3.11_numpy-2.0.0");

unpickleNumpyDtypes("python-3.11_numpy-1.23.4");
unpickleNumpyDtypes("python-3.11_numpy-1.24.1");
unpickleNumpyDtypes("python-3.11_numpy-1.26.2");
unpickleNumpyDtypes("python-3.11_numpy-2.0.0");

unpickleNumpyDatetimeDtypes("python-3.11_numpy-1.24.1");
unpickleNumpyDatetimeDtypes("python-3.11_numpy-1.26.2");
unpickleNumpyDatetimeDtypes("python-3.11_numpy-2.0.0");

unpickleNumpyRNGs("python-3.11_numpy-1.23.4");
unpickleNumpyRNGs("python-3.11_numpy-1.24.1");
unpickleNumpyRNGs("python-3.11_numpy-1.26.2");
unpickleNumpyRNGs("python-3.11_numpy-2.0.0");

unpicklePandasSeries("python-3.11_pandas-1.5.1");
unpicklePandasSeries("python-3.11_pandas-1.5.2");
Expand Down Expand Up @@ -287,12 +295,16 @@ public void python312() throws Exception {
unpickleEnums("python-3.12");

unpickleNumpyArrays("python-3.12_numpy-1.26.2");
unpickleNumpyArrays("python-3.12_numpy-2.0.0");

unpickleNumpyDtypes("python-3.12_numpy-1.26.2");
unpickleNumpyDtypes("python-3.12_numpy-2.0.0");

unpickleNumpyDatetimeDtypes("python-3.12_numpy-1.26.2");
unpickleNumpyDatetimeDtypes("python-3.12_numpy-2.0.0");

unpickleNumpyRNGs("python-3.12_numpy-1.26.2");
unpickleNumpyRNGs("python-3.12_numpy-2.0.0");

unpicklePandasSeries("python-3.12_pandas-2.2.0");

Expand Down
3 changes: 3 additions & 0 deletions pmml-python/src/test/java/org/jpmml/python/FunctionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void python39() throws IOException {
unpickleNumpyFunctions("python-3.9_numpy-1.23.4");
unpickleNumpyFunctions("python-3.9_numpy-1.24.1");
unpickleNumpyFunctions("python-3.9_numpy-1.26.2");
unpickleNumpyFunctions("python-3.9_numpy-2.0.0");
}

@Test
Expand All @@ -65,13 +66,15 @@ public void python311() throws IOException {
unpickleNumpyFunctions("python-3.11_numpy-1.23.4");
unpickleNumpyFunctions("python-3.11_numpy-1.24.1");
unpickleNumpyFunctions("python-3.11_numpy-1.26.2");
unpickleNumpyFunctions("python-3.11_numpy-2.0.0");
}

@Test
public void python312() throws Exception {
unpickleMathFunctions("python-3.12_math");

unpickleNumpyFunctions("python-3.12_numpy-1.26.2");
unpickleNumpyFunctions("python-3.12_numpy-2.0.0");
}

static
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b7b402e

Please sign in to comment.