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

Alter field metadata #493

Merged
merged 1 commit into from
Oct 23, 2024
Merged

Alter field metadata #493

merged 1 commit into from
Oct 23, 2024

Conversation

sandorkertesz
Copy link
Collaborator

@sandorkertesz sandorkertesz commented Oct 21, 2024

This PR adds the copy() method to fields. The result is a new field containing:

  • reference to the values/values accessor in the original field
  • a wrapped metadata object updated with the kwargs

The original field is kept unaltered.

E.g. if f is a field with "level" = 500:

>>> f_new = f.copy(level=700)
>>> f.metadata("level")
>>> f_new.metadata("level")
500
700

The kwargs can contain callables with the signature described below:

def _func(field, key, original_metadata):
    return original_metadata[key] + 100

f_new = f.copy(level=_func)
print(f.metadata("level"))
print(f_new.metadata("level"))
500
600

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (develop@9ad0e0c). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #493   +/-   ##
==========================================
  Coverage           ?   90.73%           
==========================================
  Files              ?      144           
  Lines              ?     9896           
  Branches           ?      473           
==========================================
  Hits               ?     8979           
  Misses             ?      761           
  Partials           ?      156           

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

@b8raoult
Copy link
Contributor

original_metadata is a dict(), not a Metadata

@b8raoult b8raoult requested review from JamesVarndell and b8raoult and removed request for JamesVarndell October 22, 2024 15:24
@sandorkertesz sandorkertesz marked this pull request as ready for review October 23, 2024 07:11
@sandorkertesz sandorkertesz changed the title WIP: Alter field metadata Alter field metadata Oct 23, 2024
@sandorkertesz sandorkertesz merged commit a2804c0 into develop Oct 23, 2024
101 checks passed
@sandorkertesz sandorkertesz deleted the feature/alter-field-metadata branch October 23, 2024 07:19
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