When called inside a groupby.apply context, stack_anomalous overrides the as_index=False setting and appends the grouping column to the index of the returned dataset with name None
import numpy as np
import reciprocalspaceship as rs
cell = [34., 45., 98., 90., 90., 90.]
spacegroup = 19
dmin = 4.
repeats = 1
h,k,l = rs.utils.generate_reciprocal_asu(cell, spacegroup, dmin, anomalous=True).T
ds = None
for i in range(repeats):
_ds = rs.DataSet({
"H" : h,
"K" : k,
"L" : l,
"I" : np.random.random(len(h)),
"SIGI" : np.random.random(len(h)),
}, cell=cell, spacegroup=spacegroup, merged=True).infer_mtz_dtypes()
_ds['repeat'] = i
if ds is not None:
ds = rs.concat((ds, _ds))
else:
ds = _ds
ds = ds.set_index(['H', 'K', 'L'])
print(f"Before: {ds.index}")
# Somehow calling `stack_anomalous` overides `as_index=False`
result = ds.groupby('repeat', as_index=False).apply(lambda x: x.stack_anomalous())
print(f"After: {result.index}")
When called inside a
groupby.apply
context,stack_anomalous
overrides theas_index=False
setting and appends the grouping column to the index of the returned dataset with nameNone
which gives the following output:
The
repeat
column still persists in theresult
dataset.