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

Import R data frame attributes as metadata #93

Merged
merged 9 commits into from
Oct 10, 2022
Merged

Import R data frame attributes as metadata #93

merged 9 commits into from
Oct 10, 2022

Conversation

nalimilan
Copy link
Member

Use the metadata function that are going to be added to DataAPI and DataFrames (JuliaData/DataFrames.jl#3055) to import R data.frame attributes and set them as DataFrame metadata.
R stores per-column attributes in vector objects, while DataFrames.jl stores them in the DataFrame object, as there is no generic mechanism to attach metadata to an AbstractVector object.

The row.names attribute is skipped as it is not appropriate to store it as global metadata given that it will get out of sync after subsetting rows. We could provide a way to turn row names into a column instead.

Also add methods to check equality between two DictoVec object as these are useful for tests (haven commonly sets named numeric vectors to store value labels so this case deserves testing).

(Test pass locally when using DataAPI and DataFrame branches.)

Use the `metadata` function recently added to DataAPI and DataFrames
to import R `data.frame` attributes and set them as `DataFrame` metadata.
R stores per-column attributes in vector objects, while DataFrames.jl
stores them in the `DataFrame` object, as there is no generic mechanism
to attach metadata to an `AbstractVector` object.

The `row.names` attribute is skipped as it is not appropriate to store
it as global metadata given that it will get out of sync after subsetting
rows. We could provide a way to turn row names into a column instead.

Also add methods to check equality between two `DictoVec` objects
as these are useful for tests (haven commonly sets named numeric vectors
to store value labels so this case deserves testing).
@nalimilan nalimilan requested review from alyst and bkamins May 26, 2022 11:31
@alyst
Copy link
Collaborator

alyst commented May 26, 2022

Thanks! I'll try to review it in the next few days.

@bkamins
Copy link
Member

bkamins commented May 26, 2022

@alyst - we still need to decide on the best API in JuliaData/DataAPI.jl#48 before finalizing this PR, so if you have any thoughts on this please comment there. Thank you!

Copy link
Collaborator

@alyst alyst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I think there are useful and straightforward changes, I have just noted a few minor issues, mostly regarding handling some special situations.

src/DictoVec.jl Outdated Show resolved Hide resolved
src/convert.jl Outdated Show resolved Hide resolved
src/DictoVec.jl Show resolved Hide resolved
test/RDA.jl Outdated Show resolved Hide resolved
src/convert.jl Outdated Show resolved Hide resolved
src/convert.jl Outdated Show resolved Hide resolved
src/DictoVec.jl Show resolved Hide resolved
test/RDA.jl Show resolved Hide resolved
ZonedDateTime(2022, 05, 26, 22, 5, tz"UTC")],
:default),
"comment" => ("This is a data frame", :note),
"row.names" => ([missing, -6], :default)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alyst Any idea what might be going on here? Is this due to the fact that R stores default row names as an AltRep object?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems some conversion from R to Julia is missing, but it is not in the scope of this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alyst Do you think we should tackle this here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea yet :( I think the choice between the standard and alternative representation is dynamic and depends on e.g. the length of the vector.
I agree that it would better to address this in a separate PR + add tests that explicit "row.names" attributes are handled correctly (at least that their presence doesn't break the whole ".rda" import).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. TBH I'm not sure I'd be able to fix that but I can try to have a look.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"row.names" => ([missing, -6], :default)))
"row.names" => ([missing, -6], :default))) # FIXME check the conversion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. TBH I'm not sure I'd be able to fix that but I can try to have a look.

I'll try to have a look within 1-2 weeks.

Project.toml Outdated Show resolved Hide resolved
src/convert.jl Show resolved Hide resolved
Copy link
Member

@bkamins bkamins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks good. We need to wait for required releases and run CI.

@nalimilan nalimilan requested a review from alyst October 8, 2022 10:45
src/convert.jl Show resolved Hide resolved
src/convert.jl Show resolved Hide resolved
src/convert.jl Outdated Show resolved Hide resolved
src/convert.jl Show resolved Hide resolved
nalimilan and others added 2 commits October 9, 2022 22:20
Co-authored-by: Alexey Stukalov <[email protected]>
Co-authored-by: Bogumił Kamiński <[email protected]>
@codecov
Copy link

codecov bot commented Oct 9, 2022

Codecov Report

Base: 85.75% // Head: 86.64% // Increases project coverage by +0.88% 🎉

Coverage data is based on head (2724f62) compared to base (5df74cf).
Patch coverage: 97.14% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   85.75%   86.64%   +0.88%     
==========================================
  Files          14       14              
  Lines         646      689      +43     
==========================================
+ Hits          554      597      +43     
  Misses         92       92              
Impacted Files Coverage Δ
src/convert.jl 95.73% <96.42%> (+0.76%) ⬆️
src/DictoVec.jl 96.20% <100.00%> (-1.02%) ⬇️
src/RData.jl 100.00% <100.00%> (ø)
src/context.jl 100.00% <0.00%> (ø)
src/sxtypes.jl 76.13% <0.00%> (+0.27%) ⬆️
src/identifier.jl 92.59% <0.00%> (+0.28%) ⬆️
src/readers.jl 74.28% <0.00%> (+0.29%) ⬆️
... and 3 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@nalimilan
Copy link
Member Author

Ah, DataFrames 1.4 requires Julia 1.6, so we have to drop support for older Julia versions here too. But the convention is to bump the minor release when doing that, so that we would still be able to tag a bugfix release on 1.0 if necessary. Maybe take the occasion to tag RData 1.0?

@alyst
Copy link
Collaborator

alyst commented Oct 9, 2022

I think tagging 1.0.0 is a good idea.

@nalimilan nalimilan merged commit 880bed5 into main Oct 10, 2022
@nalimilan nalimilan deleted the nl/metadata branch October 10, 2022 06:38
@nalimilan
Copy link
Member Author

Thanks! See JuliaRegistries/General#69824

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

Successfully merging this pull request may close these issues.

3 participants