Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
This repository was archived by the owner on Aug 13, 2026. It is now read-only.

Unappropriated test recently added create ValueError exception #345

Closed

Description

@VelizarVESSELINOV

Environment details

  • OS type and version: MacOS BigSur 11.4
  • Python version: Python 3.9.2
  • pip version: pip 21.1.3
  • google-cloud-logging google-cloud-logging version: Version: 2.5.0

Steps to reproduce

Between 2.3.1 and 2.5.0
added test google/cloud/logging_v2/handlers/handlers.py", line 107, in filter
record._msg_str = str(record.msg).replace('"', '\"') if record.msg else ""

assuming that the content can be tested without the consideration that maybe it is DataFrame object that is giving ValueError due to ambiguity (The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all())

Code example

from google.cloud.logging import Client as gcp
from google.cloud.logging.handlers import setup_logging
from google.cloud.logging_v2.handlers import CloudLoggingHandler
from logging import getLogger, debug
from pandas import DataFrame

setup_logging(CloudLoggingHandler(gcp()))
getLogger().setLevel('DEBUG')

dtf = DataFrame()

debug(dtf)

Stack trace


CRITICAL:root:Exception Information
CRITICAL:root:Type: <class 'ValueError'>
CRITICAL:root:Value: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
CRITICAL:root:Traceback:   File "/Library/Frameworks/Python.framework/Versions/3.9/bin/dppr", line 33, in <module>
    sys.exit(load_entry_point('dpdp==0.9.1', 'console_scripts', 'dppr')())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/dpdp-0.9.1-py3.9.egg/dpdp/command_line.py", line 116, in predictor_command_line
    out = predictor(args.folder.rstrip(sep), args.campaign, args.mcs, args.verbose)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/dpdp-0.9.1-py3.9.egg/dpdp/predictor.py", line 49, in predictor
    debug(dtq)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/dpdp-0.9.1-py3.9.egg/dpdp/file_access.py", line 159, in debug
    logging_debug(msg, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 2103, in debug
    root.debug(msg, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1430, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1585, in _log
    self.handle(record)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1595, in handle
    self.callHandlers(record)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 1657, in callHandlers
    hdlr.handle(record)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 944, in handle
    rv = self.filter(record)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/logging/__init__.py", line 802, in filter
    result = f.filter(record)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/google/cloud/logging_v2/handlers/handlers.py", line 107, in filter
    record._msg_str = str(record.msg).replace('"', '\\"') if record.msg else ""
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/generic.py", line 1534, in __nonzero__
    raise ValueError(

Activity

  1. added
    type: questionRequest for information or clarification. Not an issue.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jul 15, 2021
  2. daniel-sanche commented on Jul 15, 2021

    @daniel-sanche
    Contributor

    Hey Velizar,

    the Python logging standard library expects the message to be a string (see docs here). Instead of logging the data frame directly, you should convert it to a string prepresentation first:

    debug(str(dtf))
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: loggingIssues related to the googleapis/python-logging API.priority: p2Moderately-important priority. Fix may not be included in next release.triage meI really want to be triaged.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions