-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Empty dataframe not equal to another empty dataframe in 0.16.1 #10181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
the |
It's these lines where the False is returned. Here's the output of my debugger at that point- >>> len(self.blocks)
Out[1]: 1
>>> len(other.blocks)
Out[2]: 0
>>> self.blocks
Out[3]: (FloatBlock: [], 0 x 0, dtype: float64,)
>>> other.blocks
Out[4]: () |
this is a symptom of where the comparison happens the issue is that a 0-Len FloatBlock is created in the first place |
Here's some background on why we needed this functionality- We have a container class that looks something like this (paraphrased, just to avoid any issues with pasting any actual working code from my employer) class Container(object):
def __init__(self, a, b):
self.a = a
self.b = b
@classmethod
def empty(cls):
return cls(pd.DataFrame(), pd.DataFrame())
def __eq__(self, other):
return (type(other) is type(self)
and self.a.equals(other.a)
and self.b.equals(other.b))
def __add__(self, other):
return Container(self.a + other.a, self.b + other.b)
def __radd__(self, other):
return self.__add__(other)
def __iadd__(self, other):
return self.__add__(other) This container class holds a grouping of results, which we want to be able to add to each other. (The addition isn't as simple as in this implementation, otherwise obviously we could just use panels). We need to be able to have things like this work: empty = Container.empty()
def f(c):
# in reality, perform some operation on c
# that can sometimes return an empty container
return Container.empty()
def g(c):
# in reality, perform some operation on c
# that can sometimes return an empty container
return Container.empty()
c = Container(pd.DataFrame([1],[1]), pd.DataFrame([2],[2]))
assert (f(c) + g(c)) == empty In [85]: pd.DataFrame().blocks
Out[85]: {}
In [86]: (pd.DataFrame() + pd.DataFrame()).blocks
Out[86]:
{'float64': Empty DataFrame
Columns: []
Index: []} |
For what it's worth, I decided to have a go. #10188 in case it is helpful. |
BUG: Adding empty dataframes should result in empty blocks #10181
I searched the issues list for "empty dataframe" but did not find anything matching.
In pandas 0.16.1, the result of adding 2 empty dataframes is not equal to another empty dataframe.
This code, in pandas 0.15.2, does what is expected:
It fails in 0.16.1.
0.15.2 output:
0.16.1 output:
The text was updated successfully, but these errors were encountered: