Git Product home page Git Product logo

Comments (1)

cliffckerr avatar cliffckerr commented on June 16, 2024

@tacaswell I agree that the first one is pretty nonintuitive, to say the least! This parallels the behavior in pandas:

import pandas as pd
pd.DataFrame(data={'a':[1,2,3]}, columns=[4,5,6])
Out[13]: 
Empty DataFrame
Columns: [4, 5, 6]
Index: []

(This "feature" has confused other people -- see e.g. here.)

As with regular pandas, you get less bizarre output if there's overlap between the input data and the column names:

sc.dataframe(a=[1, 2, 3], cols=['a','b'])
Out[3]: 
   a    b
0  1  NaN
1  2  NaN
2  3  NaN

I've added a warning if there is no overlap between the data keys and the column names, and also made the behavior consistent regardless of how the data are supplied:

sc.dataframe(a=[1, 2, 3], cols=[4, 5, 6])
/tmp/ipykernel_592135/2569439549.py:1: RuntimeWarning: No overlap between column names and data keys, are you sure you want to do this?
Columns: {4, 5, 6}
Data keys: {'a'}

Out[2]: 
Empty dataframe
Columns: [4, 5, 6]
Index: []

For the second one, I've updated the error message:

sc.dataframe(a=[1, 2, 3], data=[4, 5, 6])
Traceback (most recent call last):

  Cell In[1], line 1
    sc.dataframe(a=[1, 2, 3], data=[4, 5, 6])

  File ~/sciris/sciris/sciris/sc_dataframe.py:101 in __init__
    raise TypeError(errormsg)

TypeError: When providing data columns via keywords ("a"), these can only be combined with a dict, not an object of <class 'list'>. Pass the data as a dict instead.

from sciris.

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.