Skip to content

Commit a13e7a0

Browse files
authored
Merge pull request #436 from lincc-frameworks/fix_issue405
_metadata override for eval()
2 parents f0211a2 + 178dcde commit a13e7a0

File tree

1 file changed

+13
-0
lines changed
  • src/nested_pandas/nestedframe

1 file changed

+13
-0
lines changed

src/nested_pandas/nestedframe/core.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,19 @@ def eval(self, expr: str, *, inplace: bool = False, **kwargs) -> Any | None:
13501350
kwargs["inplace"] = inplace
13511351
kwargs["parser"] = "nested-pandas"
13521352
answer = super().eval(expr, **kwargs)
1353+
1354+
# If the result is a _SeriesFromNest, set the metadata manually
1355+
# This is a bit of a hack, as it's a backstop for super().eval()
1356+
# not propagating the metadata correctly, `for some reason`.
1357+
# Furthermore, it relies on the assumption that the first resolver
1358+
# is the only one that matters. Because we disallow multi-layer
1359+
# queries, this is potentially safe, though eval statements that target
1360+
# multiple nests may have strange behavior.
1361+
if isinstance(answer, _SeriesFromNest) and not hasattr(answer, "nest_name"):
1362+
nest_key = list(kwargs["resolvers"][0].keys())[0]
1363+
answer.nest_name = kwargs["resolvers"][0][nest_key]._nest_name
1364+
answer.flat_nest = kwargs["resolvers"][0][nest_key]._flat_nest
1365+
13531366
self._aliases = None
13541367
return answer
13551368

0 commit comments

Comments
 (0)