
pandas.core.SeriesUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pmml-python Show documentation
Show all versions of pmml-python Show documentation
JPMML Python to PMML converter
/*
* Copyright (c) 2021 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 .
*/
package pandas.core;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.jpmml.python.ClassDictUtil;
import org.jpmml.python.HasArray;
public class SeriesUtil {
private SeriesUtil(){
}
static
public Series createSeries(Index index, List> values){
HasArray hasArray = new HasArray(){
@Override
public List> getArrayContent(){
return values;
}
@Override
public int[] getArrayShape(){
return new int[]{values.size()};
}
@Override
public Object getArrayType(){
throw new UnsupportedOperationException();
}
};
SingleBlockManager singleBlockManager = new SingleBlockManager()
.setOnlyBlockItem(index)
.setOnlyBlockValue(hasArray);
Series result = new Series();
result.setBlockManager(singleBlockManager);
return result;
}
static
public Map toMap(Series series, Function keyFunction, Function valueFunction){
SingleBlockManager blockManager = series.getBlockManager();
Index blockItem = blockManager.getOnlyBlockItem();
List keys = Lists.transform((List)(blockItem.getValues()), keyFunction);
HasArray blockValue = blockManager.getOnlyBlockValue();
List values = Lists.transform((List)blockValue.getArrayContent(), valueFunction);
ClassDictUtil.checkSize(keys, values);
Map result = new LinkedHashMap<>();
for(int i = 0; i < keys.size(); i++){
result.put(keys.get(i), values.get(i));
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy