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

Change object returned for empty cfbd_stats_game_advanced response #92

Open
titaniumtroop opened this issue Apr 8, 2023 · 1 comment

Comments

@titaniumtroop
Copy link

titaniumtroop commented Apr 8, 2023

When you call cfbd_stats_game_advanced() with a valid value but receive an empty response (e.g., no games yet for 2023), the return value is an empty list. A valid response to the cfbd_stats_game_advanced returns a cfbfastR_data object. For example:

tibble(year = 2021:2023) %>%
  mutate(stats = map(year, ~ cfbd_stats_game_advanced(year = .x, season_type = "both")))
2023-04-08 12:49:21:Invalid arguments or no game advanced stats data available!
# A tibble: 3 × 2
   year stats                  
  <int> <list>                 
1  2021 <cfbfstR_ [1,692 × 60]>
2  2022 <cfbfstR_ [2,842 × 60]>
3  2023 <list [0]>   

This function does throw a warning -- but in returning objects of different types, it can cause errors in downstream processing that expects objects of the same type. For example, trying to unnest the result above generates a type conflict error:

> tibble(year = 2021:2023) %>%
+     mutate(stats = map(year, ~ cfbd_stats_game_advanced(year = .x, season_type = "both"))) %>%
+     unnest(stats)
2023-04-08 12:52:50:Invalid arguments or no game advanced stats data available!
Error in `list_unchop()`:
! Can't combine `x[[1]]` <tbl_df> and `x[[3]]` <list>.

Expected behavior
The function should either throw an error when no stats are available, or it should return the same object type as a non-empty response (i.e., cfbfastR_data). I suggest returning an empty cfbfastR_data object -- a well-formed query about a valid year (e.g., the current year) in which no games happen to have been played yet should be empty, not an error. In the example above, the correct response gets returned (stats for games in two of the three seasons specified, and none for the last) but the object type conflict prevents their combination in later processing. Expected behavior would look something like this:

tibble(year = 2021:2023) %>%
  mutate(stats = map(year, ~ cfbd_stats_game_advanced(year = .x, season_type = "both")))
2023-04-08 12:49:21: Invalid arguments or no game advanced stats data available!
# A tibble: 3 × 2
   year stats                  
  <int> <list>                 
1  2021 <cfbfstR_ [1,692 × 60]>
2  2022 <cfbfstR_ [2,842 × 60]>
3  2023 <cfbfstR_ [0 × 60]>   
@saiemgilani
Copy link
Collaborator

Fair comment, and generally agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants