Beta

Virtual Columns in pandas dataframe - Python

Description
Loading description...
Data Frames
NumPy
Arrays
Algorithms
Data Science
  • Please sign in or sign up to leave a comment.
  • FArekkusu Avatar

    Error messages should show actual/expected values.

  • Voile Avatar

    you want create a new table with the old values and with a new column with information that you obtain with the old table.

    If a new table is required, this should be tested. Currently this is not tested, and modifying the input will also affect the random tests.

    • raulpy271 Avatar

      If a new table is required, this should be tested.

      What does it mean? All test cases test the result of the function, which is the new table. Therefore, why this isn't tested? Did you said a test case to test if the input aren't changed?

    • raulpy271 Avatar

      and modifying the input will also affect the random tests.

      In this point You're right. Because I do this:

      df_result = add_virtual_column(df_valid, f"{df_valid.columns[0]}{operation}{df_valid.columns[1]}", new_label)
      df_expected =  df_valid.copy()
      

      Which can be a problem because add_virtual_column can affect the value of df_expected. Now I change the order of the statements:

      df_expected =  df_valid.copy()
      df_result = add_virtual_column(df_valid, f"{df_valid.columns[0]}{operation}{df_valid.columns[1]}", new_label)
      

      Now it can't affect df_expected. This solve the problem, did it?

    • raulpy271 Avatar

      Marking as resolved...

      Issue marked resolved by raulpy271 3 years ago
    • Voile Avatar

      Did you said a test case to test if the input aren't changed?

      Yup

  • Voile Avatar

    The kata's requirement is ill-formed at the moment: expressions like 2 or label_one + 1 are perfectly valid expressions but will be rejected according to the kata's requirement because 2 is being considered a label instead of a number.

    • raulpy271 Avatar

      Make sense that role can be values as 2 or label_one + 1. But hadn't added this in the kata's requirement because it would add more complexity to te kata's. Therefore, the goal of the kata's is deal only with roles of the form: {label_one} {operation} {label_two}. So I don't think that what you said is a problem, is only a kata's design decision.

      What do you think?

    • raulpy271 Avatar

      Marking as resolved...

      Issue marked resolved by raulpy271 3 years ago
  • Voile Avatar

    Needs a test case where the dataframe contains invalid labels but role contains only valid labels.

    Actually, what is the expected handling in this case?

    • raulpy271 Avatar

      In this situation, the function should return an empty dataframe too. I added this assertation:

      df = pd.DataFrame([[1, 2]] * 3, columns = ["label-one", "label_two"])
      test.expect(add_virtual_column(df, "label_one + label_two", "label").empty, "Should return an empty df when a df column is invalid")
      

      So, I think that this is solved. Thanks!

      Issue marked resolved by raulpy271 3 years ago
  • FArekkusu Avatar

    test.expect should provide meaningful error messages.

  • FArekkusu Avatar

    Tests are using old-test-framework-style it blocks.

  • FArekkusu Avatar

    Test framework and solution should be imported explicitly.