question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

skip_missing is gone, how to skip None elements ?

See original GitHub issue

I saw that v2.0.0b removed the skip_missing option, claiming it skips the missing entries by default. However in my case (using mongoengine’s Document) a field is never missing: it returns None which is, strictly speaking, something

I can see from the commit (https://github.com/marshmallow-code/marshmallow/commit/a3908d36967ac30764ceb66c52c99357425fbdec) that previous behavior of skipping empty values (like None or empty list/tuple) has been obliterated. Is there now a new way to do this ?

I’m thinking for now to overload the _serialize method of each field to check for the empty value and return the missing singleton in such a case… but this sound really cumbersome to me, there must be a better way !

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

30reactions
sloriacommented, May 23, 2017

Sorry for the delayed response on this.

How about using a post-dump method to remove any null values? Something like:

from marshmallow import Schema, fields, post_dump

class BaseSchema(Schema):
    SKIP_VALUES = set([None])

    @post_dump
    def remove_skip_values(self, data):
        return {
            key: value for key, value in data.items()
            if value not in self.SKIP_VALUES
        }


class MySchema(BaseSchema):
    foo = fields.Field()
    bar = fields.Field()


sch = MySchema()
sch.dump({'foo': 42, 'bar': None}).data  # {'foo': 42}
7reactions
Bachmann1234commented, Sep 4, 2015

Howdy! Thanks @sloria for this. Though you will run into problems if you have dicts or anything not hashable. Luckily I just needed to filter Nones out so I could change it to

if value is not None

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to skip missing data in Scrapy - Stack Overflow
Try this one: def parse(self, response): for item in response.xpath('//*[@class="hehe"]'): joke = item.xpath('.
Read more >
Missing Values - Julia Documentation
As this example shows, the element type of such arrays is Union{Missing, ... In this situation, use the skipmissing function to skip missing...
Read more >
Solved: How to skip missing value? - SAS Support Communities
Solved: Hi, I want to calculate the weighted average of some variable the code looks like this Proc sql; Create table want as...
Read more >
Health checks — XClim Official Documentation
skip : Skip missing value detection. from_context : Look-up the missing ... xclim.core.missing.missing_any(da, freq, src_timestep=None, **indexer)[source].
Read more >
Miscellaneous Functions · StatsBase.jl - JuliaStats
The first element of the tuple is a vector of values of the input and the second ... skipmissing::Symbol=:none : If :none (the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found