Skip to content

WIP: Convert java arrays to Series on fetching model elements #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions ixmp/backend/jdbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,26 +508,28 @@ def item_get_elements(self, s, type, name, filters=None):
idx_sets = list(item.getIdxSets())

data = {}
types = {}

# Retrieve index columns
for d, (d_name, d_set) in enumerate(zip(idx_names, idx_sets)):
data[d_name] = item.getCol(d, jList)
if d_set == 'year':
# Record column for later type conversion
types[d_name] = int
log.debug('converting {}...'.format(d_name))
dtype = 'int16' if d_set == 'year' else 'category'
# apply trick from
# https://github.com/jpype-project/jpype/issues/71
data[d_name] = pd.Series(item.getCol(d, jList)[:], dtype=dtype)
log.debug('bytes consumed {}'.format(
data[d_name].memory_usage(deep=True)))

# Retrieve value columns
if type == 'par':
data['value'] = item.getValues(jList)
data['unit'] = item.getUnits(jList)
data['value'] = pd.Series(item.getValues(jList)[:])
data['unit'] = pd.Series(item.getUnits(jList)[:],
dtype="category")

if type in ('equ', 'var'):
data['lvl'] = item.getLevels(jList)
data['mrg'] = item.getMarginals(jList)
data['lvl'] = pd.Series(item.getLevels(jList)[:])
data['mrg'] = pd.Series(item.getMarginals(jList)[:])

return pd.DataFrame.from_dict(data, orient='columns') \
.astype(types)
return pd.DataFrame.from_dict(data, orient='columns')
elif type == 'set':
# Index sets
return pd.Series(item.getCol(0, jList))
Expand Down