Code Monkey home page Code Monkey logo

Comments (3)

asottile avatar asottile commented on August 16, 2024
df.loc[s, ]

and

df.loc[s]

are different code

the former is a 1-element tuple -- perhaps you meant to write df.loc[(s,)] ?

from add-trailing-comma.

njiles avatar njiles commented on August 16, 2024

Thanks - I thought it might be something like that, but I couldn't get it straight in my head. I guess it's a quirk/design decision of pandas that df.loc[s] and df.loc[s,]/df.loc[(s,)] should mean the same thing.

I suppose that the correct way to fix the conflict between flake8 (which prefers foo[1, ]) and this tool (which prefers foo[1,]) is to manually wrap the term in parentheses, i.e. foo[(1,)] - this seems to satisfy both tools. (Or preferably remove the comma entirely, i.e. foo[1], if that doesn't change the behaviour.)

from add-trailing-comma.

asottile avatar asottile commented on August 16, 2024

pandas may treat them the same, but they are not the same:

>>> class C:
...     def __getitem__(self, x):
...         print(x)
... 
>>> c = C()
>>> c[1,]
(1,)
>>> c[1]
1

from add-trailing-comma.

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.