Skip to content

Prevent incorrect data.table-connected metadata out of epix_as_of #561

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

Open
2 tasks
brookslogan opened this issue Nov 3, 2024 · 1 comment
Open
2 tasks
Labels
bug Something isn't working

Comments

@brookslogan
Copy link
Contributor

library(epiprocess)
#> Registered S3 method overwritten by 'tsibble':
#>   method               from 
#>   as_tibble.grouped_df dplyr
#> 
#> Attaching package: 'epiprocess'
#> The following object is masked from 'package:stats':
#> 
#>     filter
archive_cases_dv_subset %>%
  epix_as_of(as.Date("2021-11-29")) %>%
  attributes() %>%
  {.[names(.) != "row.names"]} # row.names isn't relevant, clogs output
#> $names
#> [1] "geo_value"       "time_value"      "percent_cli"     "case_rate_7d_av"
#> 
#> $class
#> [1] "epi_df"     "tbl_df"     "tbl"        "data.frame"
#> 
#> $.internal.selfref
#> <pointer: 0x55a9589a7060>
#> 
#> $sorted
#> [1] "geo_value"  "time_value" "version"   
#> 
#> $metadata
#> $metadata$geo_type
#> [1] "state"
#> 
#> $metadata$time_type
#> [1] "day"
#> 
#> $metadata$as_of
#> [1] "2021-11-29"
#> 
#> $metadata$other_keys
#> character(0)

Created on 2024-11-03 with reprex v2.1.1

.internal.selfref and sorted are used by the data.table package on data.table objects and maybe at some point some in-place conversions and mostly-internal shallow conversions. We probably should remove them. sorted's value is incorrect anyway given that there's no version column in the output. Right now I only notice it being annoying when writing some tests.

  • prevent attribute attachment; maybe as.data.frame or setDT before as_tibble
  • side question (deferrable): some attribute-related handling in data.table isn't how I remembered it; check whether the sorted attribute set in epix_detailed_restricted_mutate before setDT is actually being used anymore (/ ever?). If so, means above is more important to address
@brookslogan brookslogan added the bug Something isn't working label Nov 3, 2024
@brookslogan
Copy link
Contributor Author

I think data.table might ignore these attributes and do the right thing since the class is not data.table, so I'm not sure it's actually an active footgun, but probably good to clean up just to be safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant