Skip to content
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

Unexpected empty cell with a where condition #40

Closed
jbe456 opened this issue May 13, 2020 · 3 comments
Closed

Unexpected empty cell with a where condition #40

jbe456 opened this issue May 13, 2020 · 3 comments
Assignees
Labels
🐛 bug unexpected or wrong behavior
Milestone

Comments

@jbe456
Copy link
Contributor

jbe456 commented May 13, 2020

Steps to reproduce

import pandas as pd

dummy_df = pd.DataFrame(
    data={
        "id": [0, 1, 2, 3],
        "Name": ["John", "John", "Thomas", "Mike"],
        "Score": [10, 8, 5, 12],
    }
)

import atoti

session = atoti.create_session()
dummy_store = session.read_pandas(
    dummy_df, keys=["id"], types={"id": atoti.types.STRING, "Score": atoti.types.DOUBLE}
)
cube = session.create_cube(dummy_store)

cube.measures["underlying"] = atoti.agg.single_value(
    atoti.where(cube.measures["Score.SUM"] == 12, 1000),
    scope=atoti.scope.origin(cube.levels["Name"]),
)

cube.measures["final"] = atoti.where(cube.measures["underlying"] == None, 'NOTHING', 'SOMETHING')

Actual Result

The measure final returns an empty cell for Total Name although underlying has a value:

image

Expected Result

I would expect the final measure to return "SOMETHING" for "Total Name"

Environment

  • Atoti: 0.4.0.20200512194154
  • Python: 3.8.2
  • Operating System: linux
@jbe456 jbe456 added the 🐛 bug unexpected or wrong behavior label May 13, 2020
@fabiencelier
Copy link
Contributor

fabiencelier commented May 14, 2020

This is related to the issue #17 and the comment about the where: single_value adds Name as a required level and where uses this required level to do a "per" which make it null when Name is not expressed.
The issue is that singe value should not have required levels.

This can be reproduced like that:

m["test"] = atoti.agg.sum(
    m["Score.SUM"],
    scope=atoti.scope.origin(lvl["Name"])
)
m["test"]._required_levels # should be empty but isn't

@fabiencelier
Copy link
Contributor

My bad, I was wrong.
All the aggregation functions add required levels when using scope, but they are only transmit it to the next function in the case of single_value. If you do your use case with a tt.agg.sum instead of the single value you will have the expected result.

I will change the behavior of single value so it works as the other aggregation functions. It will only transmit the required levels if it is a store measure (m["test"] = store["test"])

@fabiencelier fabiencelier self-assigned this May 14, 2020
@fabiencelier fabiencelier added this to the Next release milestone May 18, 2020
@fabiencelier
Copy link
Contributor

Fixed in 0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug unexpected or wrong behavior
Projects
None yet
Development

No branches or pull requests

2 participants