-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame with datetime column cannot concat with non-identical columns #26288
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
import pandas as pd
a = pd.DataFrame([{'t': '1970-01-01', 'id': 1, 'v': 2}])
a.t = pd.to_datetime(a.t)
b = pd.DataFrame([{'id': 2}])
a = a.to_sparse()
b = b.to_sparse()
pd.concat([a, b]) then it will fail |
Thanks! I can indeed that this is a bug. Investigation and PR are welcome! |
We get the wrong type in concatenate_join_units 229 def concatenate_join_units(join_units, concat_axis, copy):
230 """
231 Concatenate values from several join units along selected axis.
232 """
233 if concat_axis == 0 and len(join_units) > 1:
234 # Concatenating join units along ax0 is handled in _merge_blocks.
235 raise AssertionError("Concatenating join units along axis0")
236
237 empty_dtype, upcasted_na = get_empty_dtype_and_na(join_units)
238
239 to_concat = [ju.get_reindexed_values(empty_dtype=empty_dtype,
240 upcasted_na=upcasted_na)
241 for ju in join_units]
242
243 if len(to_concat) == 1:
244 # Only one block, nothing to concatenate.
245 concat_values = to_concat[0]
246 if copy:
247 if isinstance(concat_values, np.ndarray):
248 # non-reindexed (=not yet copied) arrays are made into a view
249 # in JoinUnit.get_reindexed_values
250 if concat_values.base is not None:
251 concat_values = concat_values.copy()
252 else:
253 concat_values = concat_values.copy()
254 else:
--> 255 concat_values = _concat._concat_compat(to_concat, axis=concat_axis)
256
257 return concat_values
258
ipdb> empty_dtype, upcasted_na
(dtype('<M8[ns]'), -9223372036854775808) that should be |
I should say, this isn't at all implemented yet. #22994 will fix this. |
Marking as an enhancement in light @TomAugspurger comment |
@TomAugspurger does the removal of SparseDataFrame make this closeable? |
No. I updated the original example to use DataFrame[sparse]. Different error message, but I think the same underlying issue. |
I investigated this issue a bit, and I believe the issue is in Using the provided example, the value of Further on we check whether |
Code Sample, a copy-pastable example if possible
The text was updated successfully, but these errors were encountered: