Coder Social home page Coder Social logo

Comments (2)

robin900 avatar robin900 commented on June 6, 2024 1

@sam-s I discovered why this bug has been elusive in the past. When a dataframe has multiple columns and one of those columns is of dtype float32, float64, string, or object, calling dataframe.values causes pandas to find a common dtype for a numpy array to hold values from all the columns. And since float32, float64, string, and object dtypes all result in values that are JSON serializable, there's no bug. Only for a dataframe whose columns are all non-JSON-seralizable dtypes (like int64) does the bug surface.

The solution in PR #36 decides on 'object' as the common dtype in all cases, and uses the recommended dataframe.to_numpy method instead of the deprecated dataframe.values.

from gspread-dataframe.

robin900 avatar robin900 commented on June 6, 2024

@sam-s: Reading through all the pandas documentation, I'm torn between two possible approaches to solve this problem:

  1. Use a custom JSON serializer that supports all the pandas/numpy data types.
  2. Make pandas do the work of converting the dtypes to Python basic data types.

I'm leaning toward option 2, and I'm wondering if you think it's a good idea to use dataframe.to_numpy('object') and dataframe.index.to_numpy('object') to let pandas/numpy do the necessary type conversions. I'm getting correct results with this technique, you can see it on pull request #36 for branch int64-json-35.

from gspread-dataframe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.