Skip to content

Add S3 append() method Data Package objects, ensure $schema ends up in first position for upgrade_ functions - #362

Closed
PietrH wants to merge 12 commits into
v2from
358-schema-order
Closed

PietrH wants to merge 12 commits into
v2from
358-schema-order

Conversation

@PietrH

@PietrH PietrH commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #198

I ended up implementing a generic S3 method for append() which allowed me to set a S3 method for append.datapackage(). However, since resource objects don't have a custom class, I had to implement a helper to append lists while retaining attributes. Some attributes can never be kept while appending, such as names (because they depend on the length of the object staying the same, which is not the case for append()). Things like dimnames would also break this custom append helper, as I only added an exception for names.

Converting append() to a generic S3 method will result in a message when loading frictionless:

Attaching package: ‘frictionless’

The following object is masked from ‘package:base’:

    append

This can be avoided by not using S3 dispatch at all, and using the internal helper for packages as well. But then users will not be able to call append() on a datapackage without dropping attributes.

Furthermore, I re-added tests for the location of the $schema node in upgrade_resource() and upgrade_descriptor(). Both use the same append helper code, but upgrade_descriptor() uses the generic, anywhere in the package you can call append() on a datapackage object, if you want to append a list without dropping the object class or attributes, you need to remember to use append_with_attrs(). This also has the advantage that users can now call append() on a datapackage object, and it'll just work. The same is not true for resources.

I started work on adding a custom class for resources, but will leave that exercise for the future.

@PietrH PietrH linked an issue Aug 26, 2026 that may be closed by this pull request
2 tasks
@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (515ef67) to head (981dace).
⚠️ Report is 22 commits behind head on v2.

Additional details and impacted files
@@            Coverage Diff            @@
##                v2      #362   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        27    +1     
  Lines          757       790   +33     
=========================================
+ Hits           757       790   +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PietrH PietrH linked an issue Aug 26, 2026 that may be closed by this pull request
2 of 4 tasks
@PietrH PietrH self-assigned this Aug 26, 2026
@PietrH
PietrH marked this pull request as ready for review August 26, 2026 14:05
@PietrH
PietrH requested a review from peterdesmet August 26, 2026 14:05

@peterdesmet peterdesmet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR:

  1. Sets $schema as first property, using a new helper function append_with_attrs(), with the goal of solving #358.

  2. Adds a public append() function (using the new helper), with the goal of solving #198.

Those are very different functionalities and I find this to complex to review in one PR.

Solution

A stacked PR would have worked here, but since we can't rewrite that, I did the following:

  1. From v2, create new branch dollar-schema-first and checkout the relevant files from this PR. Commit with @PietrH as co-author created PR #366

  2. From v2, create new branch append-function and checkout the relevant files from this PR. Commit with @PietrH as co-author created PR #365

I will review those separately. The helper first, since that one is needed for 2.0.0. The second one can wait.

@peterdesmet
peterdesmet deleted the 358-schema-order branch September 10, 2026 07:13
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.

Set $schema as first attribute append() drops custom datapackage class

2 participants