Top-Level Functions#
These functions are available directly in the pandas namespace.
#include <pandas/pandas.h>
using namespace pandas;
auto df = read_csv("data.csv");
auto merged = merge(df1, df2, "key");
auto concatenated = concat({df1, df2});
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
pd_dataframe.h:33155 |
|
|
DatetimeArray |
pd_dataframe.h:44668 |
|
|
DatetimeArray |
pd_top_level.h:2292 |
|
|
DatetimeArray |
pd_top_level.h:2585 |
|
|
DatetimeArray |
pd_top_level.h:2517 |
|
|
DatetimeArray |
pd_top_level.h:2450 |
|
|
DatetimeArray |
pd_top_level.h:2480 |
|
|
pandas::Timestamp |
pd_top_level.h:2503 |
|
|
pandas::Timestamp |
pd_top_level.h:2509 |
|
|
std::map<std::string, std::vector<std::string>> |
pd_dataframe.h:28173 |
|
|
std::map<std::string, std::map<std::string, std::string>> |
pd_dataframe.h:28223 |
|
|
std::map<std::string, std::map<std::string, std::string>> |
pd_dataframe.h:28309 |
|
|
std::vector<std::map<std::string, std::string>> |
pd_dataframe.h:28262 |
|
|
std::map<std::string, std::unique_ptr<NDFrameBase>> |
pd_dataframe.h:28463 |
|
|
DictSplitResult |
pd_dataframe.h:28349 |
|
|
DictTightResult |
pd_dataframe.h:28408 |
|
|
void |
pd_dataframe.h:30540 |
|
|
void |
pd_dataframe.h:31058 |
|
|
std::vector<uint8_t> |
pd_dataframe.h:39326 |
|
|
void |
pd_dataframe.h:29916 |
|
|
std::string |
pd_dataframe.h:31162 |
|
|
std::string |
pd_dataframe.h:31544 |
|
|
std::string |
pd_dataframe.h:33363 |
|
|
Series<double> |
pd_top_level.h:2738 |
|
|
Series<double> |
pd_top_level.h:2781 |
|
|
std::vector<uint8_t> |
pd_dataframe.h:28514 |
|
|
std::vector<uint8_t> |
pd_dataframe.h:29077 |
|
|
std::vector<uint8_t> |
pd_dataframe.h:29723 |
|
|
std::vector<uint8_t> |
pd_dataframe.h:43178 |
|
|
std::vector<EvalToken> |
pd_dataframe.h:577 |
|
|
numpy::RecordArray |
pd_dataframe.h:31910 |
|
|
std::vector<std::map<std::string, std::string>> |
pd_dataframe.h:39259 |
|
|
std::optional<int64_t> |
pd_dataframe.h:30146 |
|
|
std::optional<int64_t> |
pd_dataframe.h:30464 |
|
|
std::vector<uint8_t> |
pd_dataframe.h:32183 |
|
|
std::string |
pd_dataframe.h:40588 |
|
|
std::string |
pd_dataframe.h:41010 |
|
|
pd_styler.h:2048 |
||
|
std::string |
pd_dataframe.h:42071 |
|
|
std::string |
pd_dataframe.h:41786 |
|
|
std::string |
pd_dataframe.h:41505 |
|
|
std::vector<std::string> |
pd_dataframe.h:40555 |
|
|
TimedeltaArray |
pd_top_level.h:2621 |
|
|
TimedeltaArray |
pd_top_level.h:2692 |
|
|
Dataset |
pd_dataframe.h:40375 |
Combining#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
AlignedResult<T> |
pd_dataframe_construct.h:949 |
|
|
AlignmentResult |
pd_dataframe_setitem.h:117 |
|
|
AlignedResult<T> |
pd_dataframe_construct.h:917 |
|
|
Series<std::string> |
pd_series.h:16930 |
|
|
DataFrame |
pd_dataframe.h:42991 |
|
|
DataFrame |
pd_dataframe.h:43008 |
|
|
bool |
pd_concat_series.h:46 |
|
|
bool |
pd_promote.h:1010 |
|
|
PANDASCORE_API Result |
pd_concat.h:37 |
|
|
pandas::Result |
pd_concat_series.h:66 |
|
|
std::string |
pd_exceptions.h:217 |
|
|
DataFrame |
pd_dataframe.h:43128 |
|
|
DataFrame |
pd_dataframe.h:43137 |
|
|
DataFrame |
pd_top_level.h:1930 |
|
|
DataFrame |
pd_top_level.h:2065 |
Reshaping#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
pd_dataframe.h:43048 |
|
|
DataFrame |
pd_dataframe.h:43061 |
|
|
DataFrame |
pd_dataframe.h:43073 |
|
|
DataFrame |
pd_groupby.h:3840 |
Statistics#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::vector<std::vector<int64_t>> |
pd_top_level.h:414 |
|
|
std::string |
pd_top_level.h:326 |
|
|
std::vector<std::vector<double>> |
pd_top_level.h:416 |
|
|
std::vector<std::vector<double>> |
pd_top_level.h:415 |
Conversion#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
pd_dataframe.h:33203 |
||
|
static void |
pd_dataframe.h:33212 |
Other#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
class DataFrameGroupByColumn { public: |
pd_groupby.h:696 |
|
|
throw |
pd_index.h:3515 |
|
|
pd_dataframe.h:33236 |
||
|
pd_dataframe.h:33246 |
||
|
pd_dataframe.h:33242 |
||
|
throw |
pd_series_apply_dispatch.h:815 |
|
|
throw |
pd_series_apply_dispatch.h:55 |
|
|
throw |
pd_series_apply_dispatch.h:107 |
|
|
class IndexDtype : public ExtensionDtype { public: using scalar_type = T; |
pd_index_dtype.h:32 |
|
|
pd_series.h:16351 |
||
|
std::string |
pd_promote.h:646 |
|
|
std::string |
pd_display_formats.h:38 |
|
|
void |
pd_groupby.h:3416 |
|
|
pd_groupby.h:3598 |
||
|
inline void |
pd_dateoffset.h:56 |
|
|
bool |
pd_value_classify.h:83 |
|
|
DatetimeArray |
pd_datetime_index.h:4380 |
|
|
DatetimeArray |
pd_datetime_index.h:4573 |
|
|
DatetimeArray |
pd_datetime_index.h:4597 |
|
|
DatetimeArray |
pd_datetime_index.h:4626 |
|
|
DatetimeArray |
pd_datetime_index.h:4645 |
|
|
TimedeltaArray |
pd_timedelta_index.h:3388 |
|
|
BooleanArray |
pd_boolean_array.h:1012 |
|
|
BooleanArray |
pd_boolean_array.h:1029 |
|
|
DatetimeArray |
pd_datetime_array.h:1547 |
|
|
FloatingArray<T> |
pd_floating_array.h:1113 |
|
|
FloatingArray<T> |
pd_floating_array.h:1122 |
|
|
IntegerArray<T> |
pd_integer_array.h:990 |
|
|
IntegerArray<T> |
pd_integer_array.h:998 |
|
|
StringArray |
pd_string_array.h:1194 |
|
|
StringArray |
pd_string_array.h:1201 |
|
|
TimedeltaArray |
pd_timedelta_array.h:1581 |
|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:1039 |
|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:2841 |
|
|
std::vector<std::vector<std::string>> |
pd_rename_spec_impl.h:169 |
|
|
pd_apply_visitor.h:96 |
||
|
std::string |
pd_exceptions.h:169 |
|
|
DatetimeIndex |
pd_datetime_index.h:4437 |
|
|
std::vector<std::string> |
pd_groupby.h:3760 |
|
|
std::vector<std::string> |
pd_groupby.h:3539 |
|
|
DataFrame |
pd_dataframe.h:42367 |
|
|
DataFrame |
pd_dataframe.h:42633 |
|
|
static const char* |
pd_config.h:10 |
|
|
pandas::MultiIndex |
pd_dataframe_construct.h:403 |
|
|
std::string |
pd_series_apply_dispatch.h:1282 |
|
|
std::optional<Key> |
pd_series_apply_dispatch.h:1304 |
|
|
void |
pd_series_apply_dispatch.h:1239 |
|
|
void |
pd_series_apply_dispatch.h:1211 |
|
|
pandas::ApplyCellResult |
pd_series_apply_dispatch.h:1249 |
|
|
std::string |
pd_exceptions.h:372 |
|
|
std::string |
pd_exceptions.h:349 |
|
|
std::string |
pd_exceptions.h:306 |
|
|
std::string |
pd_exceptions.h:338 |
|
|
std::string |
pd_exceptions.h:375 |
|
|
std::string |
pd_exceptions.h:382 |
|
|
std::string |
pd_dataframe_setitem.h:64 |
|
|
int |
pd_where.h:82 |
|
|
int |
pd_where.h:92 |
|
|
std::string |
pd_promote.h:532 |
|
|
std::string |
pd_categorical_array.h:2276 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe_construct.h:469 |
|
|
char |
pd_apply_result.h:153 |
|
|
std::ifstream |
pd_dataframe.h:29960 |
|
|
std::ifstream |
pd_dataframe.h:30178 |
|
|
std::regex |
pd_dataframe.h:44586 |
|
|
void |
pd_period_formatter.h:44 |
|
|
pd_period_formatter.h:90 |
||
|
DTypeInfo |
pd_dtype_classify.h:56 |
|
|
ValueClassification |
pd_value_classify.h:25 |
|
|
void |
pd_dataframe.h:42338 |
|
|
std::vector<std::vector<T>> |
pd_dataframe.h:43921 |
|
|
std::vector<std::vector<std::string>> |
pd_top_level.h:3081 |
|
|
std::vector<std::vector<numpy::bool_>> |
pd_dataframe.h:43929 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:41118 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:41564 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:41846 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:42123 |
|
|
CollectIndexUnionResult |
pd_dataframe_construct.h:880 |
|
|
std::istringstream |
pd_dataframe.h:38591 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:35025 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:37355 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:38683 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:44596 |
|
|
std::regex |
pd_period_ordinal_utils.h:534 |
|
|
std::string |
pd_dtype_override.h:241 |
|
|
static size_t |
pd_dataframe.h:40975 |
|
|
static size_t |
pd_dataframe.h:40923 |
|
|
std::vector<DateYMD> |
pd_holiday.h:204 |
|
|
TimedeltaComponents |
pd_timedelta_array.h:138 |
|
|
TimedeltaComponents |
pd_timedelta_array.h:1592 |
|
|
int64_t |
pd_resampler.h:49 |
|
|
std::vector<std::string> |
pd_groupby.h:3256 |
|
|
std::string |
pd_series.h:125 |
|
|
std::string |
pd_dataframe.h:107 |
|
|
numpy::datetime64 |
pd_datetime_index.h:4665 |
|
|
DisplayConfig |
pd_display_config.h:37 |
|
|
CutResult<T> |
pd_top_level.h:718 |
|
|
std::string |
pd_promote.h:595 |
|
|
DatetimeIndex |
pd_datetime_index.h:3801 |
|
|
DatetimeIndex |
pd_datetime_index.h:4412 |
|
|
DatetimeIndex |
pd_datetime_index.h:4658 |
|
|
int64_t |
pd_period_ordinal_utils.h:69 |
|
|
int64_t |
pd_period_ordinal_utils.h:481 |
|
|
int64_t |
pd_dataframe_construct.h:57 |
|
|
std::vector<std::optional<double>> |
pd_dataframe_construct.h:75 |
|
|
std::regex |
pd_period_ordinal_utils.h:538 |
|
|
std::regex |
pd_period_ordinal_utils.h:536 |
|
|
int64_t |
pd_period_ordinal_utils.h:166 |
|
|
int64_t |
pd_top_level.h:2407 |
|
|
int |
pd_holiday.h:47 |
|
|
int |
pd_groupby.h:3290 |
|
|
int64_t |
pd_resampler.h:39 |
|
|
void |
pd_groupby.h:3276 |
|
|
pd_groupby.h:3338 |
||
|
pd_groupby.h:3721 |
||
|
pd_groupby.h:3738 |
||
|
std::regex |
pd_period_ordinal_utils.h:532 |
|
|
std::int64_t |
pd_period_formatter.h:57 |
|
|
inline int |
pd_dateoffset.h:30 |
|
|
int |
pd_holiday.h:37 |
|
|
int |
pd_period_ordinal_utils.h:58 |
|
|
void |
pd_period_ordinal_utils.h:87 |
|
|
pd_period_ordinal_utils.h:183 |
||
|
pd_period_ordinal_utils.h:215 |
||
|
pd_period_ordinal_utils.h:248 |
||
|
pd_period_ordinal_utils.h:283 |
||
|
std::string |
pd_categorical_array.h:2297 |
|
|
void |
pd_dataframe_construct.h:266 |
|
|
TupleKeyInfo |
pd_dataframe_construct.h:322 |
|
|
std::pair<bool, std::string> |
pd_value_classify.h:72 |
|
|
numpy::datetime64 |
pd_dataframe.h:35373 |
|
|
numpy::datetime64 |
pd_dataframe.h:35402 |
|
|
int |
pd_datetime64_formatter.h:50 |
|
|
void |
pd_datetime64_formatter.h:76 |
|
|
std::int64_t |
pd_datetime64_formatter.h:39 |
|
|
DatetimeIndex |
pd_resampler.h:1741 |
|
|
DatetimeIndex |
pd_resampler.h:3892 |
|
|
std::string |
pd_dtype_classify.h:154 |
|
|
pd_dataframe.h:42034 |
||
|
pd_dataframe.h:42057 |
||
|
pd_dataframe.h:42288 |
||
|
pd_dataframe.h:42309 |
||
|
pd_dataframe.h:40887 |
||
|
pd_dataframe.h:40904 |
||
|
std::string |
pd_promote.h:63 |
|
|
std::string |
json.h:258 |
|
|
pd_dataframe.h:31286 |
||
|
oss << |
pd_dataframe.h:31753 |
|
|
oss << |
pd_dataframe.h:31765 |
|
|
oss << |
pd_dataframe.h:31783 |
|
|
oss << |
pd_dataframe.h:31793 |
|
|
oss << |
pd_dataframe.h:31817 |
|
|
std::string |
pd_datetime_utils.h:73 |
|
|
std::vector<int64_t> |
pd_rolling.h:583 |
|
|
std::ofstream |
pd_dataframe.h:29015 |
|
|
std::ofstream |
pd_dataframe.h:29659 |
|
|
std::ofstream |
pd_dataframe.h:29839 |
|
|
std::ofstream |
pd_dataframe.h:31023 |
|
|
std::ofstream |
pd_dataframe.h:33085 |
|
|
std::ifstream |
pd_dataframe.h:34680 |
|
|
std::ifstream |
pd_dataframe.h:35826 |
|
|
std::ifstream |
pd_dataframe.h:36852 |
|
|
std::ifstream |
pd_dataframe.h:37827 |
|
|
std::ifstream |
pd_dataframe.h:38567 |
|
|
std::ifstream |
pd_dataframe.h:38788 |
|
|
std::ifstream |
pd_dataframe.h:39181 |
|
|
std::ofstream |
pd_dataframe.h:40327 |
|
|
std::ofstream |
pd_excel.h:607 |
|
|
std::ifstream |
pd_excel.h:976 |
|
|
std::ifstream |
pd_top_level.h:2978 |
|
|
pd_apply_visitor.h:432 |
||
|
Series<numpy::float64> |
pd_apply_visitor.h:451 |
|
|
std::string |
pd_promote.h:568 |
|
|
void |
json.h:108 |
|
|
json.h:118 |
||
|
json_impl.h:405 |
||
|
std::string |
pd_series.h:166 |
|
|
std::int64_t |
pd_datetime64_formatter.h:60 |
|
|
int64_t |
pd_resampler.h:33 |
|
|
std::int64_t |
pd_datetime64_formatter.h:67 |
|
|
inline std::vector<std::string> |
pd_format_array.h:239 |
|
|
std::string |
pd_groupby.h:3331 |
|
|
std::string |
pd_groupby.h:3223 |
|
|
std::string |
pd_groupby.h:3296 |
|
|
std::string |
pd_groupby.h:3301 |
|
|
std::string |
pd_index.h:3454 |
|
|
std::string |
pd_datetime64_formatter.h:114 |
|
|
std::string |
pd_datetime64_formatter.h:98 |
|
|
std::string |
pd_format_helpers.h:96 |
|
|
std::string |
pd_datetime64_formatter.h:88 |
|
|
std::string |
pd_period_formatter.h:66 |
|
|
std::string |
pd_display_formats.h:216 |
|
|
std::string |
pd_display_formats.h:150 |
|
|
std::string |
pd_display_formats.h:230 |
|
|
insert_sql << |
pd_dataframe.h:30365 |
|
|
insert_sql << |
pd_dataframe.h:30372 |
|
|
insert_sql << |
pd_dataframe.h:30395 |
|
|
insert_sql << |
pd_dataframe.h:30402 |
|
|
std::string |
pd_timedelta64_formatter.h:54 |
|
|
std::string |
pd_datetime64_formatter.h:128 |
|
|
oss << |
pd_dataframe.h:31828 |
|
|
std::string |
pd_dataframe.h:38807 |
|
|
std::string |
pd_dataframe.h:38817 |
|
|
int64_t |
pd_resampler.h:218 |
|
|
int64_t |
pd_resampler.h:191 |
|
|
char |
pd_groupby.h:3531 |
|
|
int64_t |
pd_resampler.h:211 |
|
|
std::vector<std::string> |
pd_groupby.h:3793 |
|
|
json.h:264 |
||
|
pd_datetime64_formatter.h:104 |
||
|
pd_datetime64_formatter.h:120 |
||
|
json.h:262 |
||
|
pd_datetime64_formatter.h:102 |
||
|
pd_datetime64_formatter.h:118 |
||
|
pandas::Series<numpy::float64> |
pd_groupby.h:1624 |
|
|
bool |
pd_dataframe.h:42342 |
|
|
, |
pd_styler.h:777 |
|
|
, |
pd_styler.h:798 |
|
|
std::string |
json.h:168 |
|
|
std::string |
pd_dataframe_construct.h:126 |
|
|
std::string |
pd_dataframe_construct.h:168 |
|
|
int |
pd_format_helpers.h:47 |
|
|
std::string |
pd_top_level.h:1383 |
|
|
std::string |
pd_period_ordinal_utils.h:112 |
|
|
SeriesDtypeInferenceResult |
pd_series.h:450 |
|
|
void |
json.h:321 |
|
|
void |
json_impl.h:111 |
|
|
void |
pd_dataframe.h:27822 |
|
|
std::vector<std::vector<int64_t>> |
pd_groupby.h:5166 |
|
|
std::string |
pd_interval_dtype.h:42 |
|
|
IntervalArray<T> |
pd_top_level.h:1484 |
|
|
std::string |
pd_exceptions.h:280 |
|
|
std::string |
pd_exceptions.h:207 |
|
|
std::string |
pd_exceptions.h:212 |
|
|
void |
pd_dataframe.h:42351 |
|
|
std::istringstream |
pd_top_level.h:2362 |
|
|
std::istringstream |
pd_top_level.h:2549 |
|
|
std::istringstream |
pd_top_level.h:2652 |
|
|
bool |
json.h:275 |
|
|
DataFrame |
json_impl.h:318 |
|
|
DataFrame |
pd_top_level.h:2210 |
|
|
std::string |
json.h:297 |
|
|
std::string |
json.h:71 |
|
|
omap_set(out, full_key, |
json.h:124 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:37592 |
|
|
bool |
pd_dtype_classify.h:248 |
|
|
bool |
pd_dtype_classify.h:238 |
|
|
bool |
pd_dtype_classify.h:241 |
|
|
bool |
pd_dtype_classify.h:234 |
|
|
std::string |
pd_exceptions.h:154 |
|
|
bool |
pd_datetime_utils.h:53 |
|
|
pd_excel.h:1262 |
||
|
bool |
json.h:244 |
|
|
DataFrame |
pd_top_level.h:1563 |
|
|
std::istringstream |
pd_dataframe.h:35858 |
|
|
inline std::unique_ptr<ArrayFormatter> |
pd_format_array.h:207 |
|
|
inline numpy::datetime64 |
pd_dateoffset.h:63 |
|
|
std::pair<std::vector<std::string>, size_t> |
pd_display_formats.h:86 |
|
|
oss << |
pd_dataframe.h:33682 |
|
|
oss << |
pd_dataframe.h:33697 |
|
|
oss << |
pd_dataframe.h:33713 |
|
|
json_impl.h:211 |
||
|
std::unique_ptr<DateOffset> |
pd_series_shift.h:15 |
|
|
std::shared_ptr<NDFrameBase> |
pd_series_apply_dispatch.h:760 |
|
|
void |
pd_dataframe_construct.h:510 |
|
|
std::string |
pd_promote.h:89 |
|
|
Series<numpy::int64> |
pd_dataframe.h:27992 |
|
|
size_t |
pd_dataframe.h:28096 |
|
|
MultiIndex |
pd_series.h:16453 |
|
|
MultiIndex |
pd_series.h:16501 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:44001 |
|
|
inline const char* |
pd_dateoffset.h:46 |
|
|
int |
pd_groupby.h:3424 |
|
|
int |
pd_dateoffset_freq_parse.h:78 |
|
|
std::regex |
pd_period_ordinal_utils.h:530 |
|
|
std::vector<std::optional<std::string>> |
pd_top_level.h:1047 |
|
|
std::vector<std::optional<std::string>> |
pd_top_level.h:1144 |
|
|
DatetimeArray |
pd_resampler.h:1843 |
|
|
DatetimeIndex |
pd_resampler.h:1844 |
|
|
std::string |
pd_dataframe.h:36907 |
|
|
std::string |
pd_excel.h:1027 |
|
|
std::string |
pd_interval_dtype.h:234 |
|
|
std::string |
pd_interval_dtype.h:589 |
|
|
std::string |
pd_datetime_utils.h:26 |
|
|
std::string |
pd_interval_dtype.h:236 |
|
|
std::string |
pd_interval_dtype.h:616 |
|
|
std::string |
pd_period_ordinal_utils.h:584 |
|
|
std::string |
pd_resampler.h:161 |
|
|
std::string |
pd_tz_format.h:23 |
|
|
std::string |
pd_groupby.h:3233 |
|
|
DateYMD |
pd_holiday.h:126 |
|
|
std::string |
pd_exceptions.h:331 |
|
|
std::string |
pd_exceptions.h:334 |
|
|
void |
json.h:96 |
|
|
json.h:120 |
||
|
json.h:122 |
||
|
int |
pd_period_ordinal_utils.h:273 |
|
|
int |
pd_period_ordinal_utils.h:300 |
|
|
int |
pd_period_ordinal_utils.h:345 |
|
|
int |
pd_period_ordinal_utils.h:376 |
|
|
int |
pd_period_ordinal_utils.h:392 |
|
|
int |
pd_period_ordinal_utils.h:232 |
|
|
int |
pd_period_ordinal_utils.h:265 |
|
|
int |
pd_period_ordinal_utils.h:406 |
|
|
std::string |
pd_period_ordinal_utils.h:603 |
|
|
int64_t |
pd_period_ordinal_utils.h:416 |
|
|
int |
pd_period_ordinal_utils.h:361 |
|
|
int |
pd_period_ordinal_utils.h:203 |
|
|
std::string |
pd_period_formatter.h:166 |
|
|
std::string |
pd_timedelta64_formatter.h:92 |
|
|
std::vector<std::complex<double>> |
pd_series_apply_dispatch.h:124 |
|
|
pd_concat_series.h:251 |
||
|
pd_concat_series.h:276 |
||
|
std::string |
pd_promote.h:254 |
|
|
ResampleFreq |
pd_resampler.h:115 |
|
|
int |
pd_rolling.h:571 |
|
|
void |
pd_groupby.h:3200 |
|
|
pd_groupby.h:3561 |
||
|
pd_groupby.h:3747 |
||
|
int64_t |
pd_resampler.h:2125 |
|
|
int64_t |
pd_groupby.h:3362 |
|
|
DtypeOverride |
pd_dtype_override.h:213 |
|
|
pd_datetime_index.h:4023 |
||
|
pd_datetime_index.h:4048 |
||
|
pd_datetime_index.h:4074 |
||
|
ResampleFreq |
pd_resampler.h:183 |
|
|
int |
pd_groupby.h:3527 |
|
|
FreqSpec |
pd_groupby.h:3461 |
|
|
std::pair<ResampleFreq, int> |
pd_resampler.h:136 |
|
|
IntervalClosed |
pd_interval_dtype.h:58 |
|
|
int64_t |
pd_resampler.h:241 |
|
|
int64_t |
pd_offset_utils.h:27 |
|
|
PeriodFrequency |
pd_period_freq.h:45 |
|
|
int64_t |
pd_period_ordinal_utils.h:517 |
|
|
PartialDateResult |
pd_datetime_utils.h:137 |
|
|
PeriodArray |
pd_period_array.h:1141 |
|
|
std::string |
pd_period_freq.h:89 |
|
|
PeriodIndex |
pd_resampler.h:1689 |
|
|
PeriodIndex |
pd_resampler.h:3840 |
|
|
std::string |
pd_dateoffset.h:142 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:33471 |
|
|
std::string |
pd_func_dispatch.h:344 |
|
|
void |
pd_dataframe_setitem.h:293 |
|
|
pd_dataframe.h:44275 |
||
|
pd_dataframe.h:44287 |
||
|
CutResult<T> |
pd_top_level.h:979 |
|
|
CutResult<T> |
pd_top_level.h:1072 |
|
|
std::regex |
pd_period_ordinal_utils.h:528 |
|
|
std::string |
pd_datetime_utils.h:55 |
|
|
std::regex |
pd_top_level.h:1668 |
|
|
DataFrame |
pd_top_level.h:2872 |
|
|
static DataFrame |
pd_dataframe.h:34617 |
|
|
static DataFrame |
pd_dataframe.h:35505 |
|
|
static DataFrame |
pd_dataframe.h:35514 |
|
|
static DataFrame |
pd_dataframe.h:35521 |
|
|
static DataFrame |
pd_dataframe.h:35531 |
|
|
static DataFrame |
pd_dataframe.h:36816 |
|
|
static DataFrame |
pd_dataframe.h:37627 |
|
|
static DataFrame |
pd_dataframe.h:37781 |
|
|
DataFrame |
pd_top_level.h:2911 |
|
|
static DataFrame |
pd_dataframe.h:39173 |
|
|
DataFrame |
pd_top_level.h:2946 |
|
|
DataFrame |
pd_top_level.h:2968 |
|
|
DataFrame |
pd_top_level.h:3185 |
|
|
static DataFrame |
pd_dataframe.h:38277 |
|
|
DataFrame |
pd_top_level.h:3223 |
|
|
std::vector<DataFrame> |
pd_top_level.h:3265 |
|
|
static DataFrame |
pd_dataframe.h:35749 |
|
|
static DataFrame |
pd_dataframe.h:35758 |
|
|
static DataFrame |
pd_dataframe.h:35765 |
|
|
static DataFrame |
pd_dataframe.h:35797 |
|
|
static DataFrame |
pd_dataframe.h:36604 |
|
|
DataFrame |
pd_top_level.h:3296 |
|
|
static DataFrame |
pd_dataframe.h:37816 |
|
|
DataFrame |
pd_top_level.h:3313 |
|
|
DataFrame |
pd_top_level.h:3325 |
|
|
DataFrame |
pd_top_level.h:3350 |
|
|
DataFrame |
pd_top_level.h:3370 |
|
|
static DataFrame |
pd_dataframe.h:38554 |
|
|
DataFrame |
pd_top_level.h:3388 |
|
|
DataFrame |
pd_top_level.h:3407 |
|
|
DataFrame |
pd_top_level.h:3435 |
|
|
static DataFrame |
pd_dataframe.h:38774 |
|
|
DataFrame |
pd_top_level.h:3462 |
|
|
DataFrame |
pd_top_level.h:3542 |
|
|
DataFrame |
pd_top_level.h:3636 |
|
|
DataFrame |
pd_top_level.h:3675 |
|
|
pandas::MultiIndex |
pd_dataframe_construct.h:379 |
|
|
DataFrameT |
pd_dataframe_construct.h:288 |
|
|
std::string |
pd_dataframe.h:42323 |
|
|
void |
pd_top_level.h:317 |
|
|
std::string |
pd_groupby.h:3967 |
|
|
std::size_t |
pd_rename_spec_impl.h:79 |
|
|
std::string |
pd_promote.h:920 |
|
|
std::string |
pd_apply_result.h:917 |
|
|
int64_t |
pd_datetime_utils.h:87 |
|
|
std::string |
pd_dataframe_construct.h:694 |
|
|
numpy::RecordArray |
pd_dataframe.h:32017 |
|
|
Timestamp |
pd_dateoffset_apply.h:49 |
|
|
DatetimeIndex |
pd_datetime_index.h:3767 |
|
|
DatetimeIndex |
pd_datetime_index.h:4387 |
|
|
DatetimeIndex |
pd_datetime_index.h:4574 |
|
|
DatetimeIndex |
pd_datetime_index.h:4598 |
|
|
DatetimeIndex |
pd_datetime_index.h:4627 |
|
|
DatetimeIndex |
pd_datetime_index.h:4646 |
|
|
pandas::Series<numpy::float64> |
pd_datetime_utils.h:114 |
|
|
DataFrameGroupBy |
pd_groupby.h:4116 |
|
|
DataFrameGroupBy |
pd_groupby.h:4128 |
|
|
DataFrameGroupBy |
pd_groupby.h:4232 |
|
|
std::vector<std::vector<double>> |
pd_top_level.h:413 |
|
|
std::vector<std::vector<std::string>> |
pd_groupby.h:5165 |
|
|
std::vector<std::optional<size_t>> |
pd_top_level.h:1965 |
|
|
int64_t |
pd_value_classify.h:66 |
|
|
ExtensionDtypeRouteResult |
pd_extension_dtype_router.h:75 |
|
|
std::string |
json.h:279 |
|
|
std::string |
pd_categorical_array.h:2302 |
|
|
std::string_view |
pd_extension_dtype_router.h:77 |
|
|
std::string |
pd_series.h:172 |
|
|
DataFrame |
pd_dataframe.h:42492 |
|
|
DataFrame |
pd_dataframe.h:42516 |
|
|
PartialKeyResult |
pd_multiindex.h:3282 |
|
|
DataFrame |
pd_dataframe.h:42757 |
|
|
DataFrame |
pd_dataframe.h:42861 |
|
|
Series<numpy::float64> |
pd_series.h:16394 |
|
|
std::vector<std::optional<std::string>> |
pd_categorical_constructors.h:14 |
|
|
void |
pd_dataframe_construct.h:834 |
|
|
void |
pd_top_level.h:2851 |
|
|
pd_dataframe.h:32093 |
||
|
pd_dataframe.h:32100 |
||
|
static void |
pd_config.h:26 |
|
|
static void |
pd_config.h:22 |
|
|
void |
pd_dataframe_construct.h:419 |
|
|
static void |
pd_config.h:18 |
|
|
void |
pd_top_level.h:309 |
|
|
pd_top_level.h:2853 |
||
|
pd_top_level.h:2856 |
||
|
pd_top_level.h:2858 |
||
|
pd_resampler.h:3018 |
||
|
pd_resampler.h:3048 |
||
|
pd_resampler.h:3068 |
||
|
pd_resampler.h:3088 |
||
|
pd_resampler.h:3119 |
||
|
pd_resampler.h:3150 |
||
|
pd_resampler.h:3185 |
||
|
pd_resampler.h:3211 |
||
|
pd_resampler.h:3237 |
||
|
pd_resampler.h:3263 |
||
|
pd_resampler.h:3516 |
||
|
pd_resampler.h:3682 |
||
|
pd_resampler.h:3695 |
||
|
pd_resampler.h:3703 |
||
|
pd_resampler.h:3715 |
||
|
pd_resampler.h:3723 |
||
|
pd_resampler.h:3732 |
||
|
pd_groupby.h:1450 |
||
|
pd_groupby.h:1708 |
||
|
pd_groupby.h:1876 |
||
|
pd_groupby.h:2119 |
||
|
pd_groupby.h:2160 |
||
|
pd_groupby.h:2213 |
||
|
pd_groupby.h:2312 |
||
|
pd_groupby.h:2344 |
||
|
pd_groupby.h:2406 |
||
|
pd_groupby.h:2567 |
||
|
pd_groupby.h:2694 |
||
|
Rolling<T> |
pd_rolling.h:606 |
|
|
pd_excel.h:215 |
||
|
std::string |
pd_top_level.h:2794 |
|
|
pandas::Series<numpy::float64> |
pd_datetime_utils.h:93 |
|
|
int |
pd_float_array_formatter.h:45 |
|
|
int |
pd_series.h:148 |
|
|
int |
pd_float_array_formatter.h:60 |
|
|
std::string |
pd_sparse_dtype.h:23 |
|
|
std::vector<std::vector<std::string>> |
pd_display_formats.h:126 |
|
|
std::vector<std::vector<std::string>> |
pd_display_formats.h:121 |
|
|
ComplexParts |
pd_series.h:103 |
|
|
std::ofstream |
pd_dataframe.h:30423 |
|
|
std::istringstream |
pd_styler.h:989 |
|
|
std::istringstream |
pd_styler.h:1038 |
|
|
std::istringstream |
pd_styler.h:1114 |
|
|
std::istringstream |
pd_styler.h:1186 |
|
|
std::istringstream |
pd_styler.h:1257 |
|
|
bool |
pd_dtype_override.h:63 |
|
|
bool |
pd_extension_dtype_router.h:54 |
|
|
class FloatingArray { |
pd_floating_array.h:42 |
|
|
class FloatingDtype : public ExtensionDtype { |
pd_floating_dtype.h:26 |
|
|
class IntegerArray { |
pd_integer_array.h:39 |
|
|
class IntegerDtype : public ExtensionDtype { |
pd_integer_dtype.h:24 |
|
|
class IntervalArray { |
pd_interval_array.h:45 |
|
|
class IntervalDtype : public ExtensionDtype { |
pd_interval_dtype.h:77 |
|
|
class Interval { |
pd_interval_dtype.h:240 |
|
|
class IntervalIndex : public ExtensionIndex<IntervalArray<T>> { |
pd_interval_index.h:43 |
|
|
StorageFamily |
pd_dtype_classify.h:221 |
|
|
HDF5Store |
pd_dataframe.h:29969 |
|
|
HDF5Store |
pd_dataframe.h:38296 |
|
|
std::vector<std::vector<std::string>> |
pd_dataframe.h:44639 |
|
|
numpy::str64 |
pd_dataframe.h:32074 |
|
|
numpy::str64 |
pd_dataframe.h:32081 |
|
|
std::istringstream |
pd_dataframe.h:34845 |
|
|
inline Styler |
pd_dataframe.h:42967 |
|
|
pandas::Timedelta |
pd_timedelta_index.h:3331 |
|
|
pandas::Timedelta |
pd_top_level.h:2643 |
|
|
int |
pd_timedelta64_formatter.h:42 |
|
|
std::int64_t |
pd_timedelta64_formatter.h:32 |
|
|
pd_dataframe.h:43209 |
||
|
int64_t |
pd_dataframe_construct.h:41 |
|
|
int64_t |
pd_dataframe_construct.h:64 |
|
|
std::vector<std::optional<double>> |
pd_dataframe_construct.h:96 |
|
|
TimedeltaIndex |
pd_timedelta_index.h:3272 |
|
|
pd_holiday.h:66 |
||
|
std::vector<EvalToken> |
pd_dataframe.h:443 |
|
|
std::string_view |
pd_dtype_override.h:68 |
|
|
void |
pd_series.h:265 |
|
|
pd_series.h:367 |
||
|
std::vector<size_t> |
pd_display_formats.h:19 |
|
|
pd_resampler.h:3532 |
||
|
pd_resampler.h:3534 |
||
|
pandas::Timestamp |
pd_datetime_index.h:4464 |
|
|
pandas::Timestamp |
pd_datetime_index.h:4492 |
|
|
pandas::Timestamp |
pd_top_level.h:2602 |
|
|
pandas::Timestamp |
pd_top_level.h:2372 |
|
|
pandas::Timestamp |
pd_top_level.h:2379 |
|
|
pandas::Timestamp |
pd_top_level.h:2542 |
|
|
pandas::Timestamp |
pd_top_level.h:2556 |
|
|
std::string |
pd_groupby.h:3428 |
|
|
std::string |
pd_groupby.h:3437 |
|
|
DataFrame |
pd_dataframe.h:42464 |
|
|
std::string |
pd_exceptions.h:394 |
|
|
std::string |
pd_exceptions.h:402 |
|
|
int64_t |
pd_top_level.h:2436 |
|
|
std::string |
pd_exceptions.h:271 |
|
|
std::string |
pd_exceptions.h:407 |
|
|
std::string |
pd_exceptions.h:424 |
|
|
std::string |
pd_exceptions.h:342 |
|
|
std::string |
pd_exceptions.h:364 |
|
|
std::string |
pd_exceptions.h:379 |
|
|
std::string |
pd_exceptions.h:367 |
|
|
std::string |
pd_exceptions.h:296 |
|
|
std::regex |
pd_period_ordinal_utils.h:585 |
|
|
std::vector<HolidayDef> |
pd_holiday.h:186 |
|
|
std::vector<std::vector<int64_t>> |
pd_top_level.h:420 |
|
|
static const char* |
pd_config.h:9 |
|
|
int |
pd_groupby.h:3435 |
|
|
int |
pd_dateoffset_freq_parse.h:65 |
|
|
DataFrame |
pd_top_level.h:1651 |
|
|
pd_dataframe.h:32542 |
||
|
pd_dataframe.h:32545 |
||
|
pd_dataframe.h:32561 |
||
|
pd_dataframe.h:32563 |
||
|
pd_dataframe.h:32703 |
||
|
pd_dataframe.h:32706 |
||
|
pd_dataframe.h:32800 |
||
|
pd_dataframe.h:32801 |
||
|
pd_dataframe.h:32802 |
||
|
pd_dataframe.h:32825 |
||
|
pd_dataframe.h:32866 |
||
|
pd_dataframe.h:32869 |
||
|
pd_dataframe.h:32872 |
||
|
pd_dataframe.h:32899 |
||
|
pd_dataframe.h:32901 |
||
|
pd_dataframe.h:32940 |
||
|
pd_dataframe.h:32988 |
||
|
pd_dataframe.h:32991 |
||
|
pd_dataframe.h:33059 |
||
|
pd_dataframe.h:33073 |
||
|
pd_dataframe.h:33075 |
||
|
pd_dataframe.h:29316 |
||
|
pd_dataframe.h:29320 |
||
|
pd_dataframe.h:29324 |
||
|
pd_dataframe.h:29328 |
||
|
pd_dataframe.h:29332 |
||
|
pd_dataframe.h:29335 |
||
|
pd_dataframe.h:29338 |
||
|
pd_dataframe.h:29341 |
||
|
pd_dataframe.h:29459 |
||
|
pd_dataframe.h:29463 |
||
|
pd_dataframe.h:29467 |
||
|
pd_dataframe.h:29471 |
||
|
pd_dataframe.h:29474 |
||
|
pd_dataframe.h:29476 |
||
|
pd_dataframe.h:29478 |
||
|
pd_dataframe.h:29480 |
||
|
pd_dataframe.h:29506 |
||
|
pd_dataframe.h:29510 |
||
|
pd_dataframe.h:29518 |
||
|
pd_dataframe.h:29521 |
||
|
pd_dataframe.h:29530 |
||
|
pd_dataframe.h:29533 |
||
|
pd_dataframe.h:29537 |
||
|
pd_dataframe.h:29543 |
||
|
pd_dataframe.h:29547 |
||
|
pd_dataframe.h:29555 |
||
|
pd_dataframe.h:29562 |
||
|
pd_dataframe.h:29566 |
||
|
pd_dataframe.h:29571 |
||
|
pd_dataframe.h:29575 |
||
|
pd_dataframe.h:29580 |
||
|
pd_dataframe.h:29585 |
||
|
pd_dataframe.h:29589 |
||
|
pd_dataframe.h:29593 |
||
|
pd_dataframe.h:29597 |
||
|
pd_dataframe.h:29601 |
||
|
pd_dataframe.h:29611 |
||
|
pd_dataframe.h:29615 |
||
|
pd_dataframe.h:29622 |
||
|
pd_dataframe.h:29626 |
||
|
pd_dataframe.h:29628 |
||
|
pd_dataframe.h:29634 |
||
|
pd_dataframe.h:39751 |
||
|
pd_dataframe.h:32729 |
||
|
pd_dataframe.h:32732 |
||
|
pd_dataframe.h:33011 |
||
|
pd_dataframe.h:33014 |
||
|
pd_dataframe.h:32689 |
||
|
pd_dataframe.h:32739 |
||
|
pd_dataframe.h:32745 |
||
|
pd_dataframe.h:32748 |
||
|
pd_dataframe.h:32977 |
||
|
pd_dataframe.h:33020 |
||
|
pd_dataframe.h:33025 |
||
|
pd_dataframe.h:33028 |
||
|
pd_dataframe.h:32711 |
||
|
pd_dataframe.h:32714 |
||
|
pd_dataframe.h:32875 |
||
|
pd_dataframe.h:32916 |
||
|
pd_dataframe.h:32995 |
||
|
pd_dataframe.h:32998 |
||
|
pd_dataframe.h:32682 |
||
|
pd_dataframe.h:32684 |
||
|
pd_dataframe.h:32719 |
||
|
pd_dataframe.h:32722 |
||
|
pd_dataframe.h:32794 |
||
|
pd_dataframe.h:32805 |
||
|
pd_dataframe.h:32808 |
||
|
pd_dataframe.h:32813 |
||
|
pd_dataframe.h:32819 |
||
|
pd_dataframe.h:32878 |
||
|
pd_dataframe.h:32974 |
||
|
pd_dataframe.h:33002 |
||
|
pd_dataframe.h:33005 |
||
|
pd_dataframe.h:33057 |
||
|
pd_dataframe.h:33060 |
||
|
pd_dataframe.h:33061 |
||
|
pd_dataframe.h:33065 |
||
|
pd_dataframe.h:33069 |
||
|
pd_dataframe.h:29790 |
||
|
pd_dataframe.h:29791 |
||
|
pd_dataframe.h:29792 |
||
|
pd_dataframe.h:32530 |
||
|
pd_dataframe.h:39565 |
||
|
pd_dataframe.h:39587 |
||
|
pd_dataframe.h:39644 |
||
|
pd_dataframe.h:39647 |
||
|
pd_dataframe.h:39762 |
||
|
pd_dataframe.h:40158 |
||
|
pd_dataframe.h:40254 |
||
|
pd_dataframe.h:40319 |
||
|
pd_dataframe.h:39567 |
||
|
pd_dataframe.h:39601 |
||
|
pd_dataframe.h:39629 |
||
|
pd_dataframe.h:29556 |
||
|
pd_dataframe.h:29576 |
||
|
pd_dataframe.h:29581 |
||
|
pd_dataframe.h:29623 |
||
|
pd_dataframe.h:29519 |
||
|
pd_dataframe.h:29534 |
||
|
pd_dataframe.h:29582 |
||
|
pd_dataframe.h:29627 |
||
|
pd_dataframe.h:29629 |
||
|
pd_dataframe.h:29635 |
||
|
pd_dataframe.h:29794 |
||
|
pd_dataframe.h:29803 |
||
|
pd_dataframe.h:29807 |
||
|
pd_dataframe.h:29818 |
||
|
pd_dataframe.h:29822 |
||
|
pd_dataframe.h:29833 |
||
|
pd_dataframe.h:32593 |
||
|
pd_dataframe.h:32609 |
||
|
pd_dataframe.h:32619 |
||
|
pd_dataframe.h:32621 |
||
|
pd_dataframe.h:32630 |
||
|
pd_dataframe.h:32692 |
||
|
pd_dataframe.h:32753 |
||
|
pd_dataframe.h:32797 |
||
|
pd_dataframe.h:32881 |
||
|
pd_dataframe.h:32893 |
||
|
pd_dataframe.h:32911 |
||
|
pd_dataframe.h:32921 |
||
|
pd_dataframe.h:32927 |
||
|
pd_dataframe.h:32929 |
||
|
pd_dataframe.h:32935 |
||
|
pd_dataframe.h:32979 |
||
|
pd_dataframe.h:33032 |
||
|
pd_dataframe.h:33058 |
||
|
pd_dataframe.h:32505 |
||
|
pd_dataframe.h:32506 |
||
|
pd_dataframe.h:32509 |
||
|
pd_dataframe.h:32510 |
||
|
pd_dataframe.h:32511 |
||
|
pd_dataframe.h:32514 |
||
|
pd_dataframe.h:32515 |
||
|
pd_dataframe.h:32516 |
||
|
pd_dataframe.h:32519 |
||
|
pd_dataframe.h:32525 |
||
|
pd_dataframe.h:32528 |
||
|
pd_dataframe.h:32534 |
||
|
pd_dataframe.h:32537 |
||
|
pd_dataframe.h:32547 |
||
|
pd_dataframe.h:32550 |
||
|
pd_dataframe.h:32565 |
||
|
pd_dataframe.h:32567 |
||
|
pd_dataframe.h:32571 |
||
|
pd_dataframe.h:32575 |
||
|
pd_dataframe.h:32579 |
||
|
pd_dataframe.h:32583 |
||
|
pd_dataframe.h:32587 |
||
|
pd_dataframe.h:32595 |
||
|
pd_dataframe.h:32599 |
||
|
pd_dataframe.h:32603 |
||
|
pd_dataframe.h:32607 |
||
|
pd_dataframe.h:32611 |
||
|
pd_dataframe.h:32615 |
||
|
pd_dataframe.h:32624 |
||
|
pd_dataframe.h:32628 |
||
|
pd_dataframe.h:32632 |
||
|
pd_dataframe.h:32636 |
||
|
pd_dataframe.h:32637 |
||
|
pd_dataframe.h:32641 |
||
|
pd_dataframe.h:32758 |
||
|
pd_dataframe.h:32762 |
||
|
pd_dataframe.h:32763 |
||
|
pd_dataframe.h:32767 |
||
|
pd_dataframe.h:32778 |
||
|
pd_dataframe.h:32830 |
||
|
pd_dataframe.h:32835 |
||
|
pd_dataframe.h:32839 |
||
|
pd_excel.h:560 |
||
|
pd_excel.h:583 |
||
|
pd_excel.h:600 |
||
|
pd_excel.h:601 |
||
|
pd_excel.h:551 |
||
|
pd_excel.h:557 |
||
|
pd_excel.h:558 |
||
|
pd_excel.h:559 |
||
|
pd_excel.h:573 |
||
|
pd_excel.h:580 |
||
|
pd_excel.h:581 |
||
|
pd_excel.h:582 |
||
|
pd_excel.h:589 |
||
|
pd_excel.h:597 |
||
|
pd_excel.h:602 |
||
|
pd_excel.h:603 |
||
|
pd_dataframe.h:32523 |
||
|
pd_dataframe.h:32540 |
||
|
pd_dataframe.h:32581 |
||
|
pd_dataframe.h:32601 |
||
|
pd_dataframe.h:29778 |
||
|
pd_dataframe.h:29809 |
||
|
pd_dataframe.h:29814 |
||
|
pd_dataframe.h:32521 |
||
|
pd_dataframe.h:32532 |
||
|
pd_dataframe.h:29801 |
||
|
pd_dataframe.h:29826 |
||
|
pd_dataframe.h:28575 |
||
|
pd_dataframe.h:28590 |
||
|
pd_dataframe.h:28596 |
||
|
pd_dataframe.h:29317 |
||
|
pd_dataframe.h:29321 |
||
|
pd_dataframe.h:29325 |
||
|
pd_dataframe.h:29333 |
||
|
pd_dataframe.h:29336 |
||
|
pd_dataframe.h:29339 |
||
|
pd_dataframe.h:29342 |
||
|
pd_dataframe.h:29460 |
||
|
pd_dataframe.h:29464 |
||
|
pd_dataframe.h:29468 |
||
|
pd_dataframe.h:29475 |
||
|
pd_dataframe.h:29477 |
||
|
pd_dataframe.h:29479 |
||
|
pd_dataframe.h:29481 |
||
|
pd_dataframe.h:29522 |
||
|
pd_dataframe.h:29531 |
||
|
pd_dataframe.h:29544 |
||
|
pd_dataframe.h:29563 |
||
|
pd_dataframe.h:29572 |
||
|
pd_dataframe.h:29577 |
||
|
pd_dataframe.h:29586 |
||
|
pd_dataframe.h:29590 |
||
|
pd_dataframe.h:29594 |
||
|
pd_dataframe.h:29598 |
||
|
pd_dataframe.h:29602 |
||
|
pd_dataframe.h:29612 |
||
|
pd_dataframe.h:29616 |
||
|
std::string |
pd_dataframe.h:36926 |
|
|
std::string |
pd_dataframe.h:36981 |
|
|
std::string |
pd_dataframe.h:37024 |
|
|
std::string |
pd_dataframe.h:37073 |
|
|
std::string |
pd_excel.h:1048 |
|
|
std::string |
pd_excel.h:1071 |
|
|
std::string |
pd_excel.h:1148 |
|
|
std::regex |
pd_period_ordinal_utils.h:526 |
|
|
int64_t |
pd_groupby.h:3267 |
|
|
pd_excel.h:944 |
Code Examples#
The following examples are extracted from the test suite.
to_clipboard (pd_test_2_all.cpp:10176)
10166 std::cout << "====================================== [OK] pd_test_swaplevel test suite ========================== " << std::endl;
10167 return 0;
10168 }
10169
10170} // namespace dataframe_tests
10171// ------------------- pd_test_swaplevel.cpp (end) -----------------------------
10172
10173// ------------------- pd_test_to_clipboard.cpp (start) -----------------------------
10174// pd_test_to_clipboard.cpp
10175// Tests for DataFrame.to_clipboard() method
10176
10177#include <iostream>
10178#include <string>
10179#include <vector>
10180#include <map>
10181#include <sstream>
10182#include <stdexcept>
10183#include <limits>
10184
10185#include "../pandas/pd_dataframe.h"
to_datetime (pd_test_3_all.cpp:13652)
13642 }
13643
13644 std::cout << " -> tests passed" << std::endl;
13645}
13646
13647// ============================================================================
13648// To Datetime / To Timedelta Tests
13649// ============================================================================
13650
13651void pd_test_top_level_to_datetime() {
13652 std::cout << "========= to_datetime() ===============================";
13653
13654 std::vector<std::string> dates = {
13655 "2023-01-15",
13656 "2023-06-20",
13657 "2023-12-31"
13658 };
13659
13660 pandas::DatetimeArray result = pandas::to_datetime(dates);
13661
13662 if (result.size() != 3) {
to_datetime (pd_test_3_all.cpp:13652)
13642 }
13643
13644 std::cout << " -> tests passed" << std::endl;
13645}
13646
13647// ============================================================================
13648// To Datetime / To Timedelta Tests
13649// ============================================================================
13650
13651void pd_test_top_level_to_datetime() {
13652 std::cout << "========= to_datetime() ===============================";
13653
13654 std::vector<std::string> dates = {
13655 "2023-01-15",
13656 "2023-06-20",
13657 "2023-12-31"
13658 };
13659
13660 pandas::DatetimeArray result = pandas::to_datetime(dates);
13661
13662 if (result.size() != 3) {
to_datetime_from_columns (pd_test_2_all.cpp:22794)
22784// =====================================================================
22785// DataFrame column assembly tests
22786// =====================================================================
22787
22788void test_to_datetime_from_columns_basic() {
22789 std::cout << " -- test_to_datetime_from_columns_basic --" << std::endl;
22790 std::vector<int> years = {2020, 2021, 2022};
22791 std::vector<int> months = {1, 6, 12};
22792 std::vector<int> days = {15, 20, 25};
22793 auto arr = pandas::to_datetime_from_columns(years, months, days);
22794 check(arr.size() == 3, "size==3");
22795
22796 auto v0 = arr[0];
22797 check(v0.has_value(), "v0_has_value");
22798 if (v0.has_value()) {
22799 pandas::Timestamp ts(v0->getValue());
22800 check(ts.year() == 2020, "v0_year==2020");
22801 check(ts.month() == 1, "v0_month==1");
22802 check(ts.day() == 15, "v0_day==15");
22803 check(ts.hour() == 0, "v0_hour==0");
to_datetime_mixed (pd_test_2_all.cpp:22721)
22711 check(ns_frac == 500000000LL, "fractional==500ms");
22712}
22713
22714// =====================================================================
22715// Mixed format tests
22716// =====================================================================
22717
22718void test_to_datetime_mixed_iso() {
22719 std::cout << " -- test_to_datetime_mixed_iso --" << std::endl;
22720 std::vector<std::string> vals = {"2020-01-01", "2020/06/15"};
22721 auto arr = pandas::to_datetime_mixed(vals);
22722 check(arr.size() == 2, "size==2");
22723 auto v0 = arr[0];
22724 check(v0.has_value(), "v0_has_value");
22725 if (v0.has_value()) {
22726 pandas::Timestamp ts(v0->getValue());
22727 check(ts.year() == 2020, "v0_year==2020");
22728 check(ts.month() == 1, "v0_month==1");
22729 check(ts.day() == 1, "v0_day==1");
22730 }
22731 auto v1 = arr[1];
to_datetime_numeric (pd_test_2_all.cpp:22585)
22575}
22576
22577// =====================================================================
22578// Numeric epoch tests
22579// =====================================================================
22580
22581void test_to_datetime_numeric_seconds() {
22582 std::cout << " -- test_to_datetime_numeric_seconds --" << std::endl;
22583 // 1490195805 seconds = 2017-03-22 15:16:45 UTC
22584 std::vector<double> vals = {1490195805.0};
22585 auto arr = pandas::to_datetime_numeric(vals, "s");
22586 check(arr.size() == 1, "size==1");
22587 auto v = arr[0];
22588 check(v.has_value(), "has_value");
22589 if (v.has_value()) {
22590 pandas::Timestamp ts(v->getValue());
22591 check(ts.year() == 2017, "year==2017");
22592 check(ts.month() == 3, "month==3");
22593 check(ts.day() == 22, "day==22");
22594 check(ts.hour() == 15, "hour==15");
22595 check(ts.minute() == 16, "min==16");
to_datetime_numeric (pd_test_2_all.cpp:22585)
22575}
22576
22577// =====================================================================
22578// Numeric epoch tests
22579// =====================================================================
22580
22581void test_to_datetime_numeric_seconds() {
22582 std::cout << " -- test_to_datetime_numeric_seconds --" << std::endl;
22583 // 1490195805 seconds = 2017-03-22 15:16:45 UTC
22584 std::vector<double> vals = {1490195805.0};
22585 auto arr = pandas::to_datetime_numeric(vals, "s");
22586 check(arr.size() == 1, "size==1");
22587 auto v = arr[0];
22588 check(v.has_value(), "has_value");
22589 if (v.has_value()) {
22590 pandas::Timestamp ts(v->getValue());
22591 check(ts.year() == 2017, "year==2017");
22592 check(ts.month() == 3, "month==3");
22593 check(ts.day() == 22, "day==22");
22594 check(ts.hour() == 15, "hour==15");
22595 check(ts.minute() == 16, "min==16");
to_datetime_scalar (pd_test_2_all.cpp:22696)
22686 }
22687}
22688
22689// =====================================================================
22690// Scalar epoch tests
22691// =====================================================================
22692
22693void test_to_datetime_scalar_int() {
22694 std::cout << " -- test_to_datetime_scalar_int --" << std::endl;
22695 // 1490195805 seconds
22696 auto ts = pandas::to_datetime_scalar(static_cast<int64_t>(1490195805), "s");
22697 check(ts.year() == 2017, "year==2017");
22698 check(ts.month() == 3, "month==3");
22699 check(ts.day() == 22, "day==22");
22700 check(ts.hour() == 15, "hour==15");
22701}
22702
22703void test_to_datetime_scalar_float() {
22704 std::cout << " -- test_to_datetime_scalar_float --" << std::endl;
22705 // 1.5 seconds = 1500000000 ns from epoch
22706 auto ts = pandas::to_datetime_scalar(1.5, "s");
to_datetime_scalar (pd_test_2_all.cpp:22696)
22686 }
22687}
22688
22689// =====================================================================
22690// Scalar epoch tests
22691// =====================================================================
22692
22693void test_to_datetime_scalar_int() {
22694 std::cout << " -- test_to_datetime_scalar_int --" << std::endl;
22695 // 1490195805 seconds
22696 auto ts = pandas::to_datetime_scalar(static_cast<int64_t>(1490195805), "s");
22697 check(ts.year() == 2017, "year==2017");
22698 check(ts.month() == 3, "month==3");
22699 check(ts.day() == 22, "day==22");
22700 check(ts.hour() == 15, "hour==15");
22701}
22702
22703void test_to_datetime_scalar_float() {
22704 std::cout << " -- test_to_datetime_scalar_float --" << std::endl;
22705 // 1.5 seconds = 1500000000 ns from epoch
22706 auto ts = pandas::to_datetime_scalar(1.5, "s");
to_dict (pd_test_1_all.cpp:13343)
13333 void pd_test_io_to_dict() {
13334 std::cout << "========= to_dict ================================";
13335
13336 std::map<std::string, std::vector<double>> data;
13337 data["A"] = {1.0, 2.0, 3.0};
13338 data["B"] = {4.0, 5.0, 6.0};
13339
13340 pandas::DataFrame df(data);
13341
13342 // Test list orientation
13343 auto dict_list = df.to_dict("list");
13344
13345 bool passed = (dict_list.count("A") > 0 && dict_list.count("B") > 0);
13346 passed = passed && (dict_list["A"].size() == 3);
13347 passed = passed && (dict_list["B"].size() == 3);
13348
13349 if (!passed) {
13350 std::cout << " [FAIL] : in pd_test_io_to_dict() : to_dict list failed" << std::endl;
13351 throw std::runtime_error("pd_test_io_to_dict failed");
13352 }
to_dict_orient_dict (pd_test_2_all.cpp:10652)
10642 // Create DataFrame with string index
10643 std::map<std::string, std::vector<int>> data = {
10644 {"col1", {1, 2}},
10645 {"col2", {3, 4}}
10646 };
10647 pandas::DataFrame df(data);
10648 std::vector<std::string> idx_vals = {"a", "b"};
10649 df.set_index(std::make_unique<pandas::Index<std::string>>(idx_vals));
10650
10651 // Test orient='dict': {column -> {index -> value}}
10652 auto result = df.to_dict_orient_dict();
10653
10654 // Verify structure
10655 if (result.size() != 2) {
10656 std::cout << " [FAIL] : in pd_test_to_dict_orient_dict() : expected 2 columns" << std::endl;
10657 throw std::runtime_error("pd_test_to_dict_orient_dict failed: wrong column count");
10658 }
10659
10660 // Verify col1
10661 auto& col1 = result["col1"];
10662 if (col1["a"] != "1" || col1["b"] != "2") {
to_dict_orient_index (pd_test_2_all.cpp:10755)
10745 // Create DataFrame with string index
10746 std::map<std::string, std::vector<int>> data = {
10747 {"col1", {1, 2}},
10748 {"col2", {3, 4}}
10749 };
10750 pandas::DataFrame df(data);
10751 std::vector<std::string> idx_vals = {"row_a", "row_b"};
10752 df.set_index(std::make_unique<pandas::Index<std::string>>(idx_vals));
10753
10754 // Test orient='index': {index -> {column -> value}}
10755 auto result = df.to_dict_orient_index();
10756
10757 // Verify structure
10758 if (result.size() != 2) {
10759 std::cout << " [FAIL] : in pd_test_to_dict_orient_index() : expected 2 rows" << std::endl;
10760 throw std::runtime_error("pd_test_to_dict_orient_index failed: wrong row count");
10761 }
10762
10763 // Verify row_a
10764 auto& row_a = result["row_a"];
10765 if (row_a["col1"] != "1" || row_a["col2"] != "3") {
to_dict_orient_records (pd_test_2_all.cpp:10688)
10678 std::cout << "========= to_dict_orient_records ================================";
10679
10680 // Create simple DataFrame
10681 std::map<std::string, std::vector<int>> data = {
10682 {"col1", {1, 2}},
10683 {"col2", {3, 4}}
10684 };
10685 pandas::DataFrame df(data);
10686
10687 // Test orient='records': [{column -> value}, ...]
10688 auto result = df.to_dict_orient_records();
10689
10690 // Verify structure - should be list of 2 dicts
10691 if (result.size() != 2) {
10692 std::cout << " [FAIL] : in pd_test_to_dict_orient_records() : expected 2 records, got " << result.size() << std::endl;
10693 throw std::runtime_error("pd_test_to_dict_orient_records failed: wrong record count");
10694 }
10695
10696 // Verify first record
10697 if (result[0]["col1"] != "1" || result[0]["col2"] != "3") {
10698 std::cout << " [FAIL] : in pd_test_to_dict_orient_records() : wrong values in first record" << std::endl;
to_dict_orient_series (pd_test_2_all.cpp:10911)
10901 void pd_test_to_dict_orient_series() {
10902 std::cout << "========= to_dict_orient_series =================================";
10903
10904 std::map<std::string, std::vector<int>> data = {
10905 {"col1", {1, 2, 3}},
10906 {"col2", {4, 5, 6}}
10907 };
10908 pandas::DataFrame df(data);
10909
10910 // Test orient='series': {column -> Series}
10911 auto result = df.to_dict_orient_series();
10912
10913 // Verify structure
10914 if (result.size() != 2) {
10915 std::cout << " [FAIL] : in pd_test_to_dict_orient_series() : expected 2 columns" << std::endl;
10916 throw std::runtime_error("pd_test_to_dict_orient_series failed: wrong column count");
10917 }
10918
10919 // Verify col1 is a valid Series
10920 if (result.find("col1") == result.end() || !result["col1"]) {
10921 std::cout << " [FAIL] : in pd_test_to_dict_orient_series() : missing or null col1" << std::endl;
to_dict_orient_split (pd_test_2_all.cpp:10791)
10781 std::cout << "========= to_dict_orient_split ==================================";
10782
10783 // Create simple DataFrame
10784 std::map<std::string, std::vector<int>> data = {
10785 {"A", {1, 2}},
10786 {"B", {3, 4}}
10787 };
10788 pandas::DataFrame df(data);
10789
10790 // Test orient='split': {index: [], columns: [], data: [[]]}
10791 auto result = df.to_dict_orient_split();
10792
10793 // Verify index
10794 if (result.index.size() != 2 || result.index[0] != "0" || result.index[1] != "1") {
10795 std::cout << " [FAIL] : in pd_test_to_dict_orient_split() : wrong index values" << std::endl;
10796 throw std::runtime_error("pd_test_to_dict_orient_split failed: wrong index");
10797 }
10798
10799 // Verify columns
10800 if (result.columns.size() != 2) {
10801 std::cout << " [FAIL] : in pd_test_to_dict_orient_split() : wrong column count" << std::endl;
to_dict_orient_tight (pd_test_2_all.cpp:10865)
10855 };
10856 pandas::DataFrame df(data);
10857
10858 // Set index with a name
10859 std::vector<std::string> idx_vals = {"x", "y"};
10860 auto idx = std::make_unique<pandas::Index<std::string>>(idx_vals);
10861 idx->set_name("row_idx");
10862 df.set_index(std::move(idx));
10863
10864 // Test orient='tight'
10865 auto result = df.to_dict_orient_tight();
10866
10867 // Verify index
10868 if (result.index.size() != 2 || result.index[0] != "x" || result.index[1] != "y") {
10869 std::cout << " [FAIL] : in pd_test_to_dict_orient_tight() : wrong index values" << std::endl;
10870 throw std::runtime_error("pd_test_to_dict_orient_tight failed: wrong index");
10871 }
10872
10873 // Verify columns
10874 if (result.columns.size() != 2) {
10875 std::cout << " [FAIL] : in pd_test_to_dict_orient_tight() : wrong column count" << std::endl;
to_excel (pd_test_2_all.cpp:3427)
3417 std::cout << "====================================== [OK] pd_test_eval test suite ========================== " << std::endl;
3418 return 0;
3419 }
3420
3421} // namespace dataframe_tests
3422// ------------------- pd_test_eval.cpp (end) -----------------------------
3423
3424// ------------------- pd_test_excel.cpp (start) -----------------------------
3425// dataframe_tests/pd_test_excel.cpp
3426// Test file for DataFrame.to_excel() method
3427
3428#include <iostream>
3429#include <fstream>
3430#include <stdexcept>
3431#include <map>
3432#include <vector>
3433#include <string>
3434#include <cmath>
3435#include <limits>
to_excel (pd_test_2_all.cpp:3427)
3417 std::cout << "====================================== [OK] pd_test_eval test suite ========================== " << std::endl;
3418 return 0;
3419 }
3420
3421} // namespace dataframe_tests
3422// ------------------- pd_test_eval.cpp (end) -----------------------------
3423
3424// ------------------- pd_test_excel.cpp (start) -----------------------------
3425// dataframe_tests/pd_test_excel.cpp
3426// Test file for DataFrame.to_excel() method
3427
3428#include <iostream>
3429#include <fstream>
3430#include <stdexcept>
3431#include <map>
3432#include <vector>
3433#include <string>
3434#include <cmath>
3435#include <limits>
to_feather (pd_test_2_all.cpp:11158)
11148 std::cout << "====================================== [OK] pd_test_to_dict test suite ==========================" << std::endl;
11149 return 0;
11150 }
11151
11152} // namespace dataframe_tests
11153// ------------------- pd_test_to_dict.cpp (end) -----------------------------
11154
11155// ------------------- pd_test_to_feather.cpp (start) -----------------------------
11156// dataframe_tests/pd_test_to_feather.cpp
11157// Comprehensive tests for DataFrame.to_feather() method (pandas-compatible)
11158
11159#include <iostream>
11160#include <fstream>
11161#include <sstream>
11162#include <stdexcept>
11163#include <vector>
11164#include <map>
11165#include <string>
11166#include <cmath>
11167#include <limits>
to_hdf (pd_test_2_all.cpp:11613)
11603 std::cout << "====================================== [OK] pd_test_to_feather test suite ==========================" << std::endl;
11604 return 0;
11605 }
11606
11607} // namespace dataframe_tests
11608// ------------------- pd_test_to_feather.cpp (end) -----------------------------
11609
11610// ------------------- pd_test_to_hdf.cpp (start) -----------------------------
11611// dataframe_tests/pd_test_to_hdf.cpp
11612// Tests for DataFrame.to_hdf() method - Updated for real HDF5 format
11613
11614#include <iostream>
11615#include <stdexcept>
11616#include <map>
11617#include <vector>
11618#include <string>
11619#include <fstream>
11620#include <cstdio>
11621
11622#include "../pandas/pd_dataframe.h"
to_html (pd_test_1_all.cpp:13438)
13428 void pd_test_io_to_html() {
13429 std::cout << "========= to_html ================================";
13430
13431 std::map<std::string, std::vector<double>> data;
13432 data["A"] = {1.0, 2.0};
13433 data["B"] = {3.0, 4.0};
13434
13435 pandas::DataFrame df(data);
13436
13437 std::string html = df.to_html();
13438
13439 // Check for key HTML elements
13440 bool has_table = (html.find("<table") != std::string::npos);
13441 bool has_thead = (html.find("<thead>") != std::string::npos);
13442 bool has_tbody = (html.find("<tbody>") != std::string::npos);
13443 bool has_th = (html.find("<th>") != std::string::npos);
13444 bool has_td = (html.find("<td>") != std::string::npos);
13445
13446 bool passed = has_table && has_thead && has_tbody && has_th && has_td;
to_latex (pd_test_2_all.cpp:9446)
9436 void pd_test_styler_to_latex() {
9437 std::cout << "========= to_latex =================================";
9438
9439 std::map<std::string, std::vector<double>> data = {
9440 {"A", {1.0, 2.0, 3.0}},
9441 {"B", {4.0, 5.0, 6.0}}
9442 };
9443 pandas::DataFrame df(data);
9444
9445 auto styler = df.style();
9446 std::string latex = styler.to_latex();
9447
9448 if (!contains(latex, "\\begin{tabular}")) {
9449 std::cout << " [FAIL] : in pd_test_styler_to_latex() : did not produce tabular environment" << std::endl;
9450 throw std::runtime_error("pd_test_styler_to_latex failed: did not produce tabular environment");
9451 }
9452 if (!contains(latex, "\\end{tabular}")) {
9453 std::cout << " [FAIL] : in pd_test_styler_to_latex() : did not close tabular environment" << std::endl;
9454 throw std::runtime_error("pd_test_styler_to_latex failed: did not close tabular environment");
9455 }
to_markdown (pd_test_1_all.cpp:13466)
13456 void pd_test_io_to_markdown() {
13457 std::cout << "========= to_markdown ============================";
13458
13459 std::map<std::string, std::vector<double>> data;
13460 data["X"] = {10.0, 20.0};
13461 data["Y"] = {30.0, 40.0};
13462
13463 pandas::DataFrame df(data);
13464
13465 std::string md = df.to_markdown();
13466
13467 // Check for markdown table elements
13468 bool has_pipe = (md.find("|") != std::string::npos);
13469 bool has_separator = (md.find("---") != std::string::npos);
13470
13471 bool passed = has_pipe && has_separator;
13472
13473 if (!passed) {
13474 std::cout << " [FAIL] : in pd_test_io_to_markdown() : invalid markdown format" << std::endl;
13475 throw std::runtime_error("pd_test_io_to_markdown failed");
to_numeric (pd_test_3_all.cpp:906)
896 throw std::runtime_error("crosstab: expected 2 rows");
897 }
898 if (ct.ncols() != 3) {
899 throw std::runtime_error("crosstab: expected 3 cols");
900 }
901 }
902
903 // Case B: pandas::to_numeric on Series<string> with errors="coerce"
904 {
905 pandas::Series<std::string> s({"1", "2", "'A'", "4.22"}, std::string("col_1"));
906 auto out = pandas::to_numeric(s, "coerce");
907 if (out.size() != 4) {
908 throw std::runtime_error("to_numeric: size mismatch");
909 }
910 if (out[0] != 1.0 || out[1] != 2.0 || out[3] != 4.22) {
911 throw std::runtime_error("to_numeric: parsed values wrong");
912 }
913 if (!std::isnan(out[2])) {
914 throw std::runtime_error("to_numeric coerce: non-numeric did not become NaN");
915 }
916 }
to_numeric (pd_test_3_all.cpp:906)
896 throw std::runtime_error("crosstab: expected 2 rows");
897 }
898 if (ct.ncols() != 3) {
899 throw std::runtime_error("crosstab: expected 3 cols");
900 }
901 }
902
903 // Case B: pandas::to_numeric on Series<string> with errors="coerce"
904 {
905 pandas::Series<std::string> s({"1", "2", "'A'", "4.22"}, std::string("col_1"));
906 auto out = pandas::to_numeric(s, "coerce");
907 if (out.size() != 4) {
908 throw std::runtime_error("to_numeric: size mismatch");
909 }
910 if (out[0] != 1.0 || out[1] != 2.0 || out[3] != 4.22) {
911 throw std::runtime_error("to_numeric: parsed values wrong");
912 }
913 if (!std::isnan(out[2])) {
914 throw std::runtime_error("to_numeric coerce: non-numeric did not become NaN");
915 }
916 }
to_orc (pd_test_2_all.cpp:13769)
13759 std::cout << "====================================== [OK] pd_test_to_markdown test suite ========================== " << std::endl;
13760 return 0;
13761 }
13762
13763} // namespace dataframe_tests
13764// ------------------- pd_test_to_markdown.cpp (end) -----------------------------
13765
13766// ------------------- pd_test_to_orc.cpp (start) -----------------------------
13767// dataframe_tests/pd_test_to_orc.cpp
13768// Tests for DataFrame.to_orc() method
13769
13770#include <iostream>
13771#include <stdexcept>
13772#include <map>
13773#include <vector>
13774#include <string>
13775#include <fstream>
13776#include <cstdio>
13777
13778#include "../pandas/pd_dataframe.h"
to_parquet (pd_test_2_all.cpp:14117)
14107 std::cout << "====================================== [OK] pd_test_to_orc test suite ==========================" << std::endl;
14108 return 0;
14109 }
14110
14111} // namespace dataframe_tests
14112// ------------------- pd_test_to_orc.cpp (end) -----------------------------
14113
14114// ------------------- pd_test_to_parquet.cpp (start) -----------------------------
14115// dataframe_tests/pd_test_to_parquet.cpp
14116// Tests for DataFrame.to_parquet() method
14117
14118#include <iostream>
14119#include <stdexcept>
14120#include <map>
14121#include <vector>
14122#include <string>
14123#include <fstream>
14124#include <cstdio>
14125
14126#include "../pandas/pd_dataframe.h"
to_pickle (pd_test_2_all.cpp:14906)
14896 std::cout << "====================================== [OK] pd_test_to_period test suite ========================== " << std::endl;
14897 return 0;
14898 }
14899
14900} // namespace dataframe_tests
14901// ------------------- pd_test_to_period.cpp (end) -----------------------------
14902
14903// ------------------- pd_test_to_pickle.cpp (start) -----------------------------
14904// dataframe_tests/pd_test_to_pickle.cpp
14905// Tests for DataFrame.to_pickle() method
14906
14907#include <iostream>
14908#include <stdexcept>
14909#include <map>
14910#include <vector>
14911#include <string>
14912#include <fstream>
14913#include <cstdio>
14914
14915#include "../pandas/pd_dataframe.h"
to_pickle (pd_test_2_all.cpp:14906)
14896 std::cout << "====================================== [OK] pd_test_to_period test suite ========================== " << std::endl;
14897 return 0;
14898 }
14899
14900} // namespace dataframe_tests
14901// ------------------- pd_test_to_period.cpp (end) -----------------------------
14902
14903// ------------------- pd_test_to_pickle.cpp (start) -----------------------------
14904// dataframe_tests/pd_test_to_pickle.cpp
14905// Tests for DataFrame.to_pickle() method
14906
14907#include <iostream>
14908#include <stdexcept>
14909#include <map>
14910#include <vector>
14911#include <string>
14912#include <fstream>
14913#include <cstdio>
14914
14915#include "../pandas/pd_dataframe.h"
to_records (pd_test_2_all.cpp:15323)
15313 std::cout << "====================================== [OK] pd_test_to_pickle test suite =========================" << std::endl;
15314 return 0;
15315 }
15316
15317} // namespace dataframe_tests
15318// ------------------- pd_test_to_pickle.cpp (end) -----------------------------
15319
15320// ------------------- pd_test_to_records.cpp (start) -----------------------------
15321// pd_test_to_records.cpp
15322// Tests for DataFrame.to_records() method
15323
15324#include <iostream>
15325#include <string>
15326#include <vector>
15327#include <map>
15328#include <cmath>
15329#include <stdexcept>
15330
15331#include "../pandas/pd_dataframe.h"
to_records_dict (pd_test_1_all.cpp:13491)
13481 void pd_test_io_to_records() {
13482 std::cout << "========= to_records =============================";
13483
13484 std::map<std::string, std::vector<double>> data;
13485 data["name"] = {1.0, 2.0, 3.0};
13486 data["value"] = {10.0, 20.0, 30.0};
13487
13488 pandas::DataFrame df(data);
13489
13490 auto records = df.to_records_dict();
13491
13492 bool passed = (records.size() == 3);
13493 if (passed && records.size() > 0) {
13494 // Each record should have all columns
13495 passed = passed && (records[0].size() == 2);
13496 }
13497
13498 if (!passed) {
13499 std::cout << " [FAIL] : in pd_test_io_to_records() : wrong number of records" << std::endl;
13500 throw std::runtime_error("pd_test_io_to_records failed");
to_sql (pd_test_2_all.cpp:15576)
15566 std::cout << "====================================== [OK] pd_test_to_records test suite ========================== " << std::endl;
15567 return 0;
15568 }
15569
15570} // namespace dataframe_tests
15571// ------------------- pd_test_to_records.cpp (end) -----------------------------
15572
15573// ------------------- pd_test_to_sql.cpp (start) -----------------------------
15574// dataframe_tests/pd_test_to_sql.cpp
15575// Tests for DataFrame.to_sql() method
15576
15577#include <iostream>
15578#include <stdexcept>
15579#include <map>
15580#include <vector>
15581#include <string>
15582#include <fstream>
15583#include <sstream>
15584#include <cstdio>
to_sql_con (pd_test_3_all.cpp:17647)
17637 bool passed = !str.empty();
17638 if (!passed) {
17639 std::cout << " [FAIL] : in pd_test_to_string_formatters()" << std::endl;
17640 throw std::runtime_error("pd_test_to_string_formatters failed");
17641 }
17642
17643 std::cout << " -> tests passed" << std::endl;
17644}
17645
17646// ============================================================================
17647// Test to_sql_con (alias for to_sql with con parameter name)
17648// ============================================================================
17649
17650void pd_test_to_sql_con() {
17651 std::cout << "========= DataFrame.to_sql_con() ======================";
17652
17653 std::map<std::string, std::vector<int>> data = {
17654 {"A", {1, 2}},
17655 {"B", {3, 4}}
17656 };
17657 pandas::DataFrame df(data);
to_stata (pd_test_2_all.cpp:16133)
16123 std::cout << "====================================== [OK] pd_test_to_sql test suite ==========================" << std::endl;
16124 return 0;
16125 }
16126
16127} // namespace dataframe_tests
16128// ------------------- pd_test_to_sql.cpp (end) -----------------------------
16129
16130// ------------------- pd_test_to_stata.cpp (start) -----------------------------
16131// pd_test_to_stata.cpp
16132// Tests for DataFrame.to_stata() method
16133
16134#include <iostream>
16135#include <fstream>
16136#include <string>
16137#include <vector>
16138#include <map>
16139#include <cstring>
16140#include <stdexcept>
16141
16142#include "../pandas/pd_dataframe.h"
to_string (pd_test_1_all.cpp:2693)
2683 pandas::PeriodArray arr_m(std::vector<std::string>{
2684 "2020-01",
2685 "NaT",
2686 "2025-06"
2687 }, "M");
2688
2689 // Year
2690 auto years = arr_m.year();
2691 auto y0 = years[0];
2692 if (!y0.has_value() || y0.value() != 2020) {
2693 std::cout << " [FAIL] : year[0] should be 2020, got " << (y0.has_value() ? std::to_string(y0.value()) : "NA") << std::endl;
2694 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[0]");
2695 }
2696
2697 auto y1 = years[1];
2698 if (y1.has_value()) {
2699 std::cout << " [FAIL] : year[1] should be NA (NaT)" << std::endl;
2700 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[1] should be NA");
2701 }
2702
2703 auto y2 = years[2];
to_string (pd_test_1_all.cpp:2693)
2683 pandas::PeriodArray arr_m(std::vector<std::string>{
2684 "2020-01",
2685 "NaT",
2686 "2025-06"
2687 }, "M");
2688
2689 // Year
2690 auto years = arr_m.year();
2691 auto y0 = years[0];
2692 if (!y0.has_value() || y0.value() != 2020) {
2693 std::cout << " [FAIL] : year[0] should be 2020, got " << (y0.has_value() ? std::to_string(y0.value()) : "NA") << std::endl;
2694 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[0]");
2695 }
2696
2697 auto y1 = years[1];
2698 if (y1.has_value()) {
2699 std::cout << " [FAIL] : year[1] should be NA (NaT)" << std::endl;
2700 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[1] should be NA");
2701 }
2702
2703 auto y2 = years[2];
to_string (pd_test_1_all.cpp:2693)
2683 pandas::PeriodArray arr_m(std::vector<std::string>{
2684 "2020-01",
2685 "NaT",
2686 "2025-06"
2687 }, "M");
2688
2689 // Year
2690 auto years = arr_m.year();
2691 auto y0 = years[0];
2692 if (!y0.has_value() || y0.value() != 2020) {
2693 std::cout << " [FAIL] : year[0] should be 2020, got " << (y0.has_value() ? std::to_string(y0.value()) : "NA") << std::endl;
2694 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[0]");
2695 }
2696
2697 auto y1 = years[1];
2698 if (y1.has_value()) {
2699 std::cout << " [FAIL] : year[1] should be NA (NaT)" << std::endl;
2700 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[1] should be NA");
2701 }
2702
2703 auto y2 = years[2];
to_string_vector (pd_test_1_all.cpp:10871)
10861 std::cout << " -> tests passed" << std::endl;
10862}
10863
10864void pd_test_extension_index_to_string_vector() {
10865 std::cout << "========= to_string_vector =========================";
10866
10867 pandas::CategoricalArray arr({"a", std::nullopt, "c"});
10868 pandas::CategoricalIndex idx(arr);
10869
10870 auto str_vec = idx.to_string_vector();
10871
10872 bool passed = (str_vec.size() == 3 &&
10873 str_vec[0] == "a" && str_vec[1] == "NA" && str_vec[2] == "c");
10874 if (!passed) {
10875 std::cout << " [FAIL] : in pd_test_extension_index_to_string_vector() : to_string_vector check failed" << std::endl;
10876 throw std::runtime_error("pd_test_extension_index_to_string_vector failed");
10877 }
10878
10879 std::cout << " -> tests passed" << std::endl;
10880}
to_timedelta (pd_test_3_all.cpp:13691)
13681 numpy::NDArray<numpy::bool_> na_mask2 = result2.isna();
13682 if (!static_cast<bool>(na_mask2.getElementAt({1}))) {
13683 std::cout << " [FAIL] : in pd_test_top_level_to_datetime() : empty string should be NA" << std::endl;
13684 throw std::runtime_error("pd_test_top_level_to_datetime failed: empty not NA");
13685 }
13686
13687 std::cout << " -> tests passed" << std::endl;
13688}
13689
13690void pd_test_top_level_to_timedelta() {
13691 std::cout << "========= to_timedelta() ==============================";
13692
13693 // Test string version
13694 std::vector<std::string> tds = {
13695 "1 days",
13696 "2 hours",
13697 "30 minutes"
13698 };
13699
13700 pandas::TimedeltaArray result = pandas::to_timedelta(tds);
to_timedelta (pd_test_3_all.cpp:13691)
13681 numpy::NDArray<numpy::bool_> na_mask2 = result2.isna();
13682 if (!static_cast<bool>(na_mask2.getElementAt({1}))) {
13683 std::cout << " [FAIL] : in pd_test_top_level_to_datetime() : empty string should be NA" << std::endl;
13684 throw std::runtime_error("pd_test_top_level_to_datetime failed: empty not NA");
13685 }
13686
13687 std::cout << " -> tests passed" << std::endl;
13688}
13689
13690void pd_test_top_level_to_timedelta() {
13691 std::cout << "========= to_timedelta() ==============================";
13692
13693 // Test string version
13694 std::vector<std::string> tds = {
13695 "1 days",
13696 "2 hours",
13697 "30 minutes"
13698 };
13699
13700 pandas::TimedeltaArray result = pandas::to_timedelta(tds);
to_xarray (pd_test_2_all.cpp:16928)
16918 std::cout << "====================================== [OK] pd_test_to_timestamp test suite ========================== " << std::endl;
16919 return 0;
16920 }
16921
16922} // namespace dataframe_tests
16923// ------------------- pd_test_to_timestamp.cpp (end) -----------------------------
16924
16925// ------------------- pd_test_to_xarray.cpp (start) -----------------------------
16926// dataframe_tests/pd_test_to_xarray.cpp
16927// Test for DataFrame.to_xarray() - Convert DataFrame to xarray Dataset
16928
16929#include <iostream>
16930#include <stdexcept>
16931#include <string>
16932#include <vector>
16933#include <map>
16934#include <memory>
16935#include <cmath>
16936
16937#include "../pandas/pd_dataframe.h"
align_empty_series_to_index (pd_test_3_all.cpp:23211)
23201 throw std::runtime_error("test_align_string: values[2] should be empty string");
23202 if (!aligned.has_missing)
23203 throw std::runtime_error("test_align_string: has_missing should be true");
23204
23205 std::cout << " -> test passed" << std::endl;
23206}
23207
23208void test_align_empty() {
23209 std::cout << "========= align_empty_series_to_index =================";
23210
23211 auto aligned = pandas::construct::align_empty_series_to_index<numpy::float64>(4);
23212
23213 if (aligned.values.size() != 4)
23214 throw std::runtime_error("test_align_empty: expected 4 values");
23215 for (size_t i = 0; i < 4; ++i) {
23216 if (!aligned.missing_mask[i])
23217 throw std::runtime_error("test_align_empty: missing_mask[" +
23218 std::to_string(i) + "] should be true");
23219 }
23220 if (!aligned.has_missing)
23221 throw std::runtime_error("test_align_empty: has_missing should be true");
align_series_to_dataframe (pd_test_5_all.cpp:90968)
90958static bool is_nan(double v) {
90959 return v != v;
90960}
90961
90962void case_1_positional_int64() {
90963 int local_fail = 0;
90964 auto df = make_abc_frame();
90965 auto s = make_labelled_series<std::int64_t>(
90966 {10, 20, 30}, {"a", "b", "c"});
90967 auto r = pandas::align_series_to_dataframe<std::int64_t>(
90968 s, df.index(), /*preserve_dtype=*/true);
90969
90970 check_shape("case_1_positional_int64", r, 3,
90971 pandas::SetItemResult::POSITIONAL, local_fail);
90972 pandas_tests::check(r.has_nan_from_upcasting == false,
90973 "case_1_positional_int64.no_nan_introduced", local_fail);
90974 pandas_tests::check(r.dtype_override.has_value(),
90975 "case_1_positional_int64.dtype_override_present", local_fail);
90976 pandas_tests::check(r.aligned_values[0] == 10.0 &&
90977 r.aligned_values[1] == 20.0 &&
align_series_to_index (pd_test_3_all.cpp:23163)
23153void test_align_float64() {
23154 std::cout << "========= align_series_to_index float64 ===============";
23155
23156 // Series [1,2,3] with index ["a","b","c"] -> target ["a","c","d"] = [1,3,NaN]
23157 pandas::Index<std::string> idx(std::vector<std::string>{"a", "b", "c"});
23158 pandas::Series<numpy::float64> s(
23159 std::vector<numpy::float64>{1.0, 2.0, 3.0}, idx);
23160
23161 std::vector<std::string> target = {"a", "c", "d"};
23162 auto aligned = pandas::construct::align_series_to_index(s, target);
23163
23164 if (aligned.values.size() != 3)
23165 throw std::runtime_error("test_align_float64: expected 3 values");
23166 if (aligned.values[0] != 1.0)
23167 throw std::runtime_error("test_align_float64: values[0] should be 1.0");
23168 if (aligned.values[1] != 3.0)
23169 throw std::runtime_error("test_align_float64: values[1] should be 3.0");
23170 if (!aligned.missing_mask[2])
23171 throw std::runtime_error("test_align_float64: missing_mask[2] should be true");
23172 if (aligned.missing_mask[0] || aligned.missing_mask[1])
concat (pd_test_1_all.cpp:17717)
17707}
17708
17709void pd_test_period_index_concat() {
17710 std::cout << "========= concat factory ==============================";
17711
17712 std::vector<int64_t> ordinals1 = {0, 1};
17713 std::vector<int64_t> ordinals2 = {2, 3};
17714 pandas::PeriodIndex idx1(ordinals1, "D");
17715 pandas::PeriodIndex idx2(ordinals2, "D");
17716
17717 pandas::PeriodIndex concatenated = pandas::PeriodIndex::concat({idx1, idx2});
17718
17719 bool passed = (concatenated.size() == 4);
17720 if (!passed) {
17721 std::cout << " [FAIL] : in pd_test_period_index_concat()" << std::endl;
17722 throw std::runtime_error("pd_test_period_index_concat failed");
17723 }
17724
17725 std::cout << " -> tests passed" << std::endl;
17726}
concat (pd_test_1_all.cpp:17717)
17707}
17708
17709void pd_test_period_index_concat() {
17710 std::cout << "========= concat factory ==============================";
17711
17712 std::vector<int64_t> ordinals1 = {0, 1};
17713 std::vector<int64_t> ordinals2 = {2, 3};
17714 pandas::PeriodIndex idx1(ordinals1, "D");
17715 pandas::PeriodIndex idx2(ordinals2, "D");
17716
17717 pandas::PeriodIndex concatenated = pandas::PeriodIndex::concat({idx1, idx2});
17718
17719 bool passed = (concatenated.size() == 4);
17720 if (!passed) {
17721 std::cout << " [FAIL] : in pd_test_period_index_concat()" << std::endl;
17722 throw std::runtime_error("pd_test_period_index_concat failed");
17723 }
17724
17725 std::cout << " -> tests passed" << std::endl;
17726}
concat_bool_partner_kind (pd_test_5_all.cpp:102198)
102188}
102189
102190static void check_partner_kind(const std::string& label,
102191 const std::vector<std::string>& canon,
102192 bool expected,
102193 int& local_fail) {
102194 std::cout << "-- " << label << "\n";
102195 bool got = false;
102196 std::string err;
102197 try {
102198 got = pandas::concat_bool_partner_kind(canon);
102199 } catch (const std::exception& e) {
102200 err = e.what();
102201 } catch (...) {
102202 err = "<unknown>";
102203 }
102204 pandas_tests::check(err.empty(), label + "()_no_throw", local_fail);
102205 if (!err.empty()) {
102206 std::cout << " err: " << err << "\n";
102207 return;
102208 }
concat_bool_partner_kind (pd_test_5_all.cpp:102198)
102188}
102189
102190static void check_partner_kind(const std::string& label,
102191 const std::vector<std::string>& canon,
102192 bool expected,
102193 int& local_fail) {
102194 std::cout << "-- " << label << "\n";
102195 bool got = false;
102196 std::string err;
102197 try {
102198 got = pandas::concat_bool_partner_kind(canon);
102199 } catch (const std::exception& e) {
102200 err = e.what();
102201 } catch (...) {
102202 err = "<unknown>";
102203 }
102204 pandas_tests::check(err.empty(), label + "()_no_throw", local_fail);
102205 if (!err.empty()) {
102206 std::cout << " err: " << err << "\n";
102207 return;
102208 }
concat_dispatch (pd_test_5_all.cpp:113473)
113463 check_dtype("concat_dispatch_o7p8q9_disjoint_widening",
113464 df, "float64", local_fail);
113465 bool len_ok = (df.nrows() == 4);
113466 pandas_tests::check(len_ok, "concat_dispatch_o7p8q9_disjoint_widening.nrows_4",
113467 local_fail);
113468}
113469
113470static void f_concat_dispatch_o7p8q9_case_H1_dispatch_empty(int& local_fail) {
113471 std::cout << "-- case_H1_dispatch_empty\n";
113472 std::vector<pandas::FuncArg> inputs;
113473 pandas::Result r = pandas::concat_dispatch(inputs);
113474 bool got = std::holds_alternative<std::unique_ptr<pandas::DataFrame>>(r.value);
113475 pandas_tests::check(got, "case_H1.empty_returns_dataframe", local_fail);
113476 if (!got) return;
113477 auto& dfp = std::get<std::unique_ptr<pandas::DataFrame>>(r.value);
113478 pandas_tests::check(dfp->nrows() == 0, "case_H1.nrows_0", local_fail);
113479}
113480
113481static void f_concat_dispatch_o7p8q9_case_H2_dispatch_empty_axis1(int& local_fail) {
113482 std::cout << "-- case_H2_dispatch_empty_axis1\n";
113483 std::vector<pandas::FuncArg> inputs;
concat_dispatch_series_mixed (pd_test_5_all.cpp:102135)
102125 return std::static_pointer_cast<pandas::NDFrameBase>(s);
102126}
102127
102128static pandas::Result try_concat(
102129 const std::vector<std::shared_ptr<pandas::NDFrameBase>>& inputs,
102130 const std::vector<std::string>& dtypes_full,
102131 std::string& caught_msg,
102132 bool ignore_index = true) {
102133 caught_msg.clear();
102134 try {
102135 return pandas::concat_dispatch_series_mixed(inputs, dtypes_full,
102136 ignore_index);
102137 } catch (const std::exception& e) {
102138 caught_msg = e.what();
102139 } catch (...) {
102140 caught_msg = "<unknown>";
102141 }
102142 return pandas::Result{};
102143}
102144
102145static std::string result_dtype(const pandas::Result& r) {
join_must_be_inner_or_outer_got (pd_test_5_all.cpp:73163)
73153 pandas::error_messages::invalid_join_type("left"),
73154 "case_2.long_form_distinct_from_short_form",
73155 local_fail);
73156}
73157
73158void case_3_join_inner_outer_helper(int& local_fail) {
73159 std::cout << "-- case_3_join_inner_outer_helper\n";
73160 check_eq_str(
73161 "case_3.join_inner_outer_xyz",
73162 "join must be 'inner' or 'outer', got 'xyz'",
73163 pandas::error_messages::join_must_be_inner_or_outer_got("xyz"),
73164 local_fail);
73165 check_eq_str(
73166 "case_3.join_inner_outer_empty",
73167 "join must be 'inner' or 'outer', got ''",
73168 pandas::error_messages::join_must_be_inner_or_outer_got(""),
73169 local_fail);
73170}
73171
73172void case_4_join_outer_inner_left_right(int& local_fail) {
73173 std::cout << "-- case_4_join_outer_inner_left_right\n";
merge (pd_test_1_all.cpp:13639)
13629namespace dataframe_tests {
13630 namespace dataframe_tests_joining {
13631
13632 // Helper to check approximate equality
13633 bool approx_equal(double a, double b, double tol = 1e-9) {
13634 if (std::isnan(a) && std::isnan(b)) return true;
13635 return std::abs(a - b) < tol;
13636 }
13637
13638 // =====================================================================
13639 // merge() Tests
13640 // =====================================================================
13641
13642 void pd_test_joining_merge_inner() {
13643 std::cout << "========= merge inner join ============================";
13644
13645 // Left DataFrame: id, value_left
13646 std::map<std::string, std::vector<double>> left_data = {
13647 {"id", {1.0, 2.0, 3.0, 4.0}},
13648 {"value_left", {10.0, 20.0, 30.0, 40.0}}
13649 };
merge (pd_test_1_all.cpp:13639)
13629namespace dataframe_tests {
13630 namespace dataframe_tests_joining {
13631
13632 // Helper to check approximate equality
13633 bool approx_equal(double a, double b, double tol = 1e-9) {
13634 if (std::isnan(a) && std::isnan(b)) return true;
13635 return std::abs(a - b) < tol;
13636 }
13637
13638 // =====================================================================
13639 // merge() Tests
13640 // =====================================================================
13641
13642 void pd_test_joining_merge_inner() {
13643 std::cout << "========= merge inner join ============================";
13644
13645 // Left DataFrame: id, value_left
13646 std::map<std::string, std::vector<double>> left_data = {
13647 {"id", {1.0, 2.0, 3.0, 4.0}},
13648 {"value_left", {10.0, 20.0, 30.0, 40.0}}
13649 };
merge_asof (pd_test_3_all.cpp:13741)
13731 }
13732
13733 std::cout << " -> tests passed" << std::endl;
13734}
13735
13736// ============================================================================
13737// Merge Asof / Merge Ordered Tests
13738// ============================================================================
13739
13740void pd_test_top_level_merge_asof() {
13741 std::cout << "========= merge_asof() ================================";
13742
13743 // Create left DataFrame
13744 std::map<std::string, std::vector<double>> left_data = {
13745 {"time", {1.0, 5.0, 10.0}},
13746 {"value_left", {100.0, 200.0, 300.0}}
13747 };
13748 pandas::DataFrame left(left_data);
13749
13750 // Create right DataFrame
13751 std::map<std::string, std::vector<double>> right_data = {
merge_ordered (pd_test_3_all.cpp:13775)
13765 // Should have columns from both DataFrames
13766 if (result.ncols() < 3) {
13767 std::cout << " [FAIL] : in pd_test_top_level_merge_asof() : expected at least 3 columns" << std::endl;
13768 throw std::runtime_error("pd_test_top_level_merge_asof failed: wrong column count");
13769 }
13770
13771 std::cout << " -> tests passed" << std::endl;
13772}
13773
13774void pd_test_top_level_merge_ordered() {
13775 std::cout << "========= merge_ordered() =============================";
13776
13777 std::map<std::string, std::vector<double>> left_data = {
13778 {"key", {1.0, 3.0, 5.0}},
13779 {"val_a", {10.0, 30.0, 50.0}}
13780 };
13781 pandas::DataFrame left(left_data);
13782
13783 std::map<std::string, std::vector<double>> right_data = {
13784 {"key", {2.0, 4.0, 6.0}},
13785 {"val_b", {20.0, 40.0, 60.0}}
melt (pd_test_1_all.cpp:6846)
6836 }
6837
6838 // Test melt
6839 {
6840 std::map<std::string, std::vector<int>> data;
6841 data["id"] = {1, 2};
6842 data["A"] = {10, 20};
6843 data["B"] = {30, 40};
6844 pandas::DataFrame df(data);
6845
6846 auto melted = df.melt({"id"});
6847 if (melted.nrows() != 4) { // 2 ids * 2 value columns
6848 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt nrows != 4, got " << melted.nrows() << std::endl;
6849 throw std::runtime_error("pd_test_dataframe_reshape failed: melt nrows");
6850 }
6851 if (!melted.has_column("variable")) {
6852 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt missing 'variable' column" << std::endl;
6853 throw std::runtime_error("pd_test_dataframe_reshape failed: melt variable column");
6854 }
6855 if (!melted.has_column("value")) {
6856 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt missing 'value' column" << std::endl;
melt (pd_test_1_all.cpp:6846)
6836 }
6837
6838 // Test melt
6839 {
6840 std::map<std::string, std::vector<int>> data;
6841 data["id"] = {1, 2};
6842 data["A"] = {10, 20};
6843 data["B"] = {30, 40};
6844 pandas::DataFrame df(data);
6845
6846 auto melted = df.melt({"id"});
6847 if (melted.nrows() != 4) { // 2 ids * 2 value columns
6848 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt nrows != 4, got " << melted.nrows() << std::endl;
6849 throw std::runtime_error("pd_test_dataframe_reshape failed: melt nrows");
6850 }
6851 if (!melted.has_column("variable")) {
6852 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt missing 'variable' column" << std::endl;
6853 throw std::runtime_error("pd_test_dataframe_reshape failed: melt variable column");
6854 }
6855 if (!melted.has_column("value")) {
6856 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt missing 'value' column" << std::endl;
melt (pd_test_1_all.cpp:6846)
6836 }
6837
6838 // Test melt
6839 {
6840 std::map<std::string, std::vector<int>> data;
6841 data["id"] = {1, 2};
6842 data["A"] = {10, 20};
6843 data["B"] = {30, 40};
6844 pandas::DataFrame df(data);
6845
6846 auto melted = df.melt({"id"});
6847 if (melted.nrows() != 4) { // 2 ids * 2 value columns
6848 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt nrows != 4, got " << melted.nrows() << std::endl;
6849 throw std::runtime_error("pd_test_dataframe_reshape failed: melt nrows");
6850 }
6851 if (!melted.has_column("variable")) {
6852 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt missing 'variable' column" << std::endl;
6853 throw std::runtime_error("pd_test_dataframe_reshape failed: melt variable column");
6854 }
6855 if (!melted.has_column("value")) {
6856 std::cout << " [FAIL] : in pd_test_dataframe_reshape() : melt missing 'value' column" << std::endl;
pivot_table_with_grouper (pd_test_2_all.cpp:21310)
21300 << dataframe_tests_misc_migration::g_fail << " failed)" << std::endl;
21301
21302 return dataframe_tests_misc_migration::g_fail;
21303}
21304
21305} // namespace dataframe_tests
21306// ------------------- pd_test_misc_migration.cpp (end) -----------------------------
21307
21308// ------------------- pd_test_pivot_ext.cpp (start) -----------------------------
21309// pd_test_pivot_ext.cpp - Tests for pivot_table extensions
21310// Tests pivot_table_multi_agg(), pivot_table_with_grouper(), auto-detect numeric columns
21311
21312#include <iostream>
21313#include <string>
21314#include <vector>
21315#include <cmath>
21316#include <set>
21317
21318#include "../pandas/pd_dataframe.h"
21319#include "../pandas/pd_groupby.h"
counts (pd_test_1_all.cpp:1394)
1384 pandas::DatetimeArray arr(std::vector<std::string>{
1385 "2023-01-01",
1386 "NaT",
1387 "2023-12-31",
1388 "NaT"
1389 });
1390
1391 // fillna
1392 // Fix A: storage is always ns; the boxed fill scalar comes back at ns
1393 // resolution. Compare ns counts (not toString) to be storage-unit-agnostic.
1394 numpy::datetime64 fill_val("2023-06-15");
1395 auto filled = arr.fillna(fill_val);
1396 if (filled[1].value().toNanoseconds() != fill_val.toNanoseconds()) {
1397 std::cout << " [FAIL] : fillna: NaT should be replaced" << std::endl;
1398 throw std::runtime_error("pd_test_datetime_array_fillna_dropna failed: fillna");
1399 }
1400
1401 // dropna
1402 auto dropped = arr.dropna();
1403 if (dropped.size() != 2) {
describe_option (pd_test_3_all.cpp:13415)
13405 // Test reset_option
13406 pandas::reset_option("display.max_rows");
13407 max_rows = pandas::get_option<int64_t>("display.max_rows");
13408 if (max_rows != 60) {
13409 std::cout << " [FAIL] : in pd_test_top_level_options() : reset_option failed" << std::endl;
13410 throw std::runtime_error("pd_test_top_level_options failed: reset_option");
13411 }
13412
13413 // Test describe_option
13414 std::string desc = pandas::describe_option("display.max_rows");
13415 if (desc.empty() || desc.find("display.max_rows") == std::string::npos) {
13416 std::cout << " [FAIL] : in pd_test_top_level_options() : describe_option empty or missing key" << std::endl;
13417 throw std::runtime_error("pd_test_top_level_options failed: describe_option");
13418 }
13419
13420 // Test invalid option
13421 bool threw = false;
13422 try {
13423 pandas::get_option<int64_t>("invalid.option.name");
13424 } catch (const std::exception&) {
DuplicateLabelError (pd_test_5_all.cpp:72295)
72285}
72286
72287void case_6_throw_via_registry(int& local_fail) {
72288 std::cout << "-- case_6_throw_via_registry\n";
72289 std::string caught;
72290 try {
72291 // DuplicateLabelError currently lives in pandasPython/
72292 // bindings_common.h; plan_88a moves it into pandas::. If
72293 // plan_88a hasn't landed yet this is a compile error and
72294 // documents the dependency.
72295 throw pandas::DuplicateLabelError(
72296 std::string(pandas::error_messages::kCannotReindexDuplicate));
72297 } catch (const std::exception& e) {
72298 caught = e.what();
72299 }
72300 check_eq_str(
72301 "case_6.DuplicateLabelError_round_trip",
72302 "cannot reindex on an axis with duplicate labels",
72303 caught,
72304 local_fail);
72305}
GlobalUnlock (pd_test_2_all.cpp:10220)
10210 return "";
10211 }
10212
10213 char* pszText = static_cast<char*>(GlobalLock(hData));
10214 if (pszText == nullptr) {
10215 CloseClipboard();
10216 return "";
10217 }
10218
10219 std::string text(pszText);
10220 GlobalUnlock(hData);
10221 CloseClipboard();
10222
10223 return text;
10224 }
10225#else
10226 std::string get_clipboard_text() {
10227 // Non-Windows: just return empty (can't easily read clipboard)
10228 return "";
10229 }
10230#endif
IncompatibleDataArgError (pd_test_5_all.cpp:75723)
75713 bool caught_func = false;
75714 try {
75715 throw pandas::IncompatibleFuncArgError("from pd_exceptions.h");
75716 } catch (const pandas::IncompatibleFuncArgError& e) {
75717 caught_func = (std::string(e.what()) == "from pd_exceptions.h");
75718 } catch (...) {}
75719 pandas_tests::check(caught_func, "case_1.func_arg_visible_in_pd_exceptions_h", local_fail);
75720
75721 bool caught_data = false;
75722 try {
75723 throw pandas::IncompatibleDataArgError("from pd_exceptions.h");
75724 } catch (const pandas::IncompatibleDataArgError& e) {
75725 caught_data = (std::string(e.what()) == "from pd_exceptions.h");
75726 } catch (...) {}
75727 pandas_tests::check(caught_data, "case_1.data_arg_visible_in_pd_exceptions_h", local_fail);
75728
75729 if (local_fail > 0) throw std::runtime_error("case_1 failed");
75730 std::cout << " -> case_1 passed\n";
75731}
75732
75733void case_2_exists_via_legacy_dispatch_include() {
IncompatibleFuncArgError (pd_test_5_all.cpp:75705)
75695 throw std::runtime_error("f_test_value_error_messages_3 failed");
75696 }
75697 std::cout << " -> tests passed" << std::endl;
75698}
75699
75700// --- f_test_dispatch_sentinels_3.cpp ---
75701
75702namespace f_test_dispatch_sentinels_3_ns {
75703
75704static void dispatch_call_emulator(const std::string& method) {
75705 throw pandas::IncompatibleFuncArgError(
75706 std::string("FuncDispatcher::call: no registered implementation for '") + method + "'");
75707}
75708
75709void case_1_exists_in_pd_exceptions_h() {
75710 std::cout << "----- case_1_exists_in_pd_exceptions_h -----\n";
75711 int local_fail = 0;
75712
75713 bool caught_func = false;
75714 try {
75715 throw pandas::IncompatibleFuncArgError("from pd_exceptions.h");
IncompatibleFuncArgError (pd_test_5_all.cpp:75705)
75695 throw std::runtime_error("f_test_value_error_messages_3 failed");
75696 }
75697 std::cout << " -> tests passed" << std::endl;
75698}
75699
75700// --- f_test_dispatch_sentinels_3.cpp ---
75701
75702namespace f_test_dispatch_sentinels_3_ns {
75703
75704static void dispatch_call_emulator(const std::string& method) {
75705 throw pandas::IncompatibleFuncArgError(
75706 std::string("FuncDispatcher::call: no registered implementation for '") + method + "'");
75707}
75708
75709void case_1_exists_in_pd_exceptions_h() {
75710 std::cout << "----- case_1_exists_in_pd_exceptions_h -----\n";
75711 int local_fail = 0;
75712
75713 bool caught_func = false;
75714 try {
75715 throw pandas::IncompatibleFuncArgError("from pd_exceptions.h");
Series (pd_test_1_all.cpp:11161)
11151 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0}, "values");
11152
11153 // Pipe applies function to entire Series
11154 auto add_mean = [](const pandas::Series<double>& ser, double offset) {
11155 auto mean_val = ser.mean();
11156 std::vector<double> result;
11157 for (size_t i = 0; i < ser.size(); ++i) {
11158 result.push_back(ser[i] + mean_val.value_or(0.0) + offset);
11159 }
11160 return pandas::Series<double>(result, ser.name());
11161 };
11162
11163 auto result = s.pipe(add_mean, 10.0);
11164
11165 bool passed = true;
11166 // mean is 2.5, offset is 10.0, so each value + 12.5
11167 std::vector<double> expected = {13.5, 14.5, 15.5, 16.5};
11168 for (size_t i = 0; i < result.size(); ++i) {
11169 if (!approx_equal(result[i], expected[i])) {
11170 passed = false;
adjoin (pd_test_3_all.cpp:25672)
25662// ------------------- pd_test_index_type_id (end) ------------------
25663
25664// ------------------- pd_test_display_formats (start) -----------------------------
25665// Tests for pandas/pd_display_formats.h formatting utilities
25666
25667namespace dataframe_tests_display_formats {
25668
25669void pd_test_display_formats_adjoin_basic() {
25670 std::cout << "========= display::adjoin basic =======================";
25671 std::vector<std::vector<std::string>> cols = {{"a", "bb"}, {"xxx", "y"}};
25672 std::string result = ::pandas::display::adjoin(1, cols);
25673 std::string expected = "a xxx\nbb y ";
25674 if (result != expected) {
25675 throw std::runtime_error("adjoin basic failed: got [" + result + "]");
25676 }
25677 std::cout << " -> tests passed" << std::endl;
25678}
25679
25680void pd_test_display_formats_adjoin_unequal() {
25681 std::cout << "========= display::adjoin unequal lengths =============";
25682 std::vector<std::vector<std::string>> cols = {{"a", "b", "c"}, {"x"}};
all_whole_numbers (pd_test_3_all.cpp:25515)
25505 std::cout << "========= round_ns_1000() ==============================";
25506 int64_t r = pandas::round_ns_1000(1500000000123456789.0);
25507 if (r % 1000 != 0)
25508 throw std::runtime_error("round_ns_1000 failed: not 1000-aligned");
25509 if (pandas::round_ns_1000(0.0) != 0)
25510 throw std::runtime_error("round_ns_1000 failed: zero");
25511 std::cout << " -> tests passed" << std::endl;
25512}
25513
25514void pd_test_value_classify_whole_numbers() {
25515 std::cout << "========= all_whole_numbers() ==========================";
25516 std::vector<double> v1 = {1.0, 2.0, 3.0};
25517 if (!pandas::all_whole_numbers(v1))
25518 throw std::runtime_error("all_whole_numbers failed: all whole");
25519 std::vector<double> v2 = {1.0, 2.5, 3.0};
25520 if (pandas::all_whole_numbers(v2))
25521 throw std::runtime_error("all_whole_numbers failed: has fraction");
25522 std::vector<double> v3 = {1.0, std::numeric_limits<double>::quiet_NaN(), 3.0};
25523 if (!pandas::all_whole_numbers(v3))
25524 throw std::runtime_error("all_whole_numbers failed: NaN ignored");
25525 std::cout << " -> tests passed" << std::endl;
arr (pd_test_1_all.cpp:45)
35 std::cout << " [FAIL] : in pd_test_boolean_array_constructors() : initializer_list size != 4" << std::endl;
36 throw std::runtime_error("pd_test_boolean_array_constructors failed: initializer_list size != 4");
37 }
38
39 std::cout << " -> tests passed" << std::endl;
40 }
41
42 void pd_test_boolean_array_na_handling() {
43 std::cout << "========= BooleanArray: NA handling ======================= ";
44
45 pandas::BooleanArray arr({
46 std::optional<bool>(true),
47 std::nullopt, // NA at index 1
48 std::optional<bool>(false)
49 });
50
51 if (!arr.is_na(1)) {
52 std::cout << " [FAIL] : in pd_test_boolean_array_na_handling() : is_na(1) should be true" << std::endl;
53 throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(1) should be true");
54 }
arr (pd_test_1_all.cpp:45)
35 std::cout << " [FAIL] : in pd_test_boolean_array_constructors() : initializer_list size != 4" << std::endl;
36 throw std::runtime_error("pd_test_boolean_array_constructors failed: initializer_list size != 4");
37 }
38
39 std::cout << " -> tests passed" << std::endl;
40 }
41
42 void pd_test_boolean_array_na_handling() {
43 std::cout << "========= BooleanArray: NA handling ======================= ";
44
45 pandas::BooleanArray arr({
46 std::optional<bool>(true),
47 std::nullopt, // NA at index 1
48 std::optional<bool>(false)
49 });
50
51 if (!arr.is_na(1)) {
52 std::cout << " [FAIL] : in pd_test_boolean_array_na_handling() : is_na(1) should be true" << std::endl;
53 throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(1) should be true");
54 }
arr (pd_test_1_all.cpp:45)
35 std::cout << " [FAIL] : in pd_test_boolean_array_constructors() : initializer_list size != 4" << std::endl;
36 throw std::runtime_error("pd_test_boolean_array_constructors failed: initializer_list size != 4");
37 }
38
39 std::cout << " -> tests passed" << std::endl;
40 }
41
42 void pd_test_boolean_array_na_handling() {
43 std::cout << "========= BooleanArray: NA handling ======================= ";
44
45 pandas::BooleanArray arr({
46 std::optional<bool>(true),
47 std::nullopt, // NA at index 1
48 std::optional<bool>(false)
49 });
50
51 if (!arr.is_na(1)) {
52 std::cout << " [FAIL] : in pd_test_boolean_array_na_handling() : is_na(1) should be true" << std::endl;
53 throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(1) should be true");
54 }
arr (pd_test_1_all.cpp:45)
35 std::cout << " [FAIL] : in pd_test_boolean_array_constructors() : initializer_list size != 4" << std::endl;
36 throw std::runtime_error("pd_test_boolean_array_constructors failed: initializer_list size != 4");
37 }
38
39 std::cout << " -> tests passed" << std::endl;
40 }
41
42 void pd_test_boolean_array_na_handling() {
43 std::cout << "========= BooleanArray: NA handling ======================= ";
44
45 pandas::BooleanArray arr({
46 std::optional<bool>(true),
47 std::nullopt, // NA at index 1
48 std::optional<bool>(false)
49 });
50
51 if (!arr.is_na(1)) {
52 std::cout << " [FAIL] : in pd_test_boolean_array_na_handling() : is_na(1) should be true" << std::endl;
53 throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(1) should be true");
54 }
arr (pd_test_1_all.cpp:45)
35 std::cout << " [FAIL] : in pd_test_boolean_array_constructors() : initializer_list size != 4" << std::endl;
36 throw std::runtime_error("pd_test_boolean_array_constructors failed: initializer_list size != 4");
37 }
38
39 std::cout << " -> tests passed" << std::endl;
40 }
41
42 void pd_test_boolean_array_na_handling() {
43 std::cout << "========= BooleanArray: NA handling ======================= ";
44
45 pandas::BooleanArray arr({
46 std::optional<bool>(true),
47 std::nullopt, // NA at index 1
48 std::optional<bool>(false)
49 });
50
51 if (!arr.is_na(1)) {
52 std::cout << " [FAIL] : in pd_test_boolean_array_na_handling() : is_na(1) should be true" << std::endl;
53 throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(1) should be true");
54 }
arr (pd_test_1_all.cpp:45)
35 std::cout << " [FAIL] : in pd_test_boolean_array_constructors() : initializer_list size != 4" << std::endl;
36 throw std::runtime_error("pd_test_boolean_array_constructors failed: initializer_list size != 4");
37 }
38
39 std::cout << " -> tests passed" << std::endl;
40 }
41
42 void pd_test_boolean_array_na_handling() {
43 std::cout << "========= BooleanArray: NA handling ======================= ";
44
45 pandas::BooleanArray arr({
46 std::optional<bool>(true),
47 std::nullopt, // NA at index 1
48 std::optional<bool>(false)
49 });
50
51 if (!arr.is_na(1)) {
52 std::cout << " [FAIL] : in pd_test_boolean_array_na_handling() : is_na(1) should be true" << std::endl;
53 throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(1) should be true");
54 }
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
array (pd_test_1_all.cpp:7343)
7333 };
7334 pandas::DatetimeIndex idx(values, "with_nat");
7335
7336 bool passed = (idx.size() == 3);
7337 if (!passed) {
7338 std::cout << " [FAIL] : in pd_test_datetime_index_optional_vector_constructor()" << std::endl;
7339 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7340 }
7341
7342 // Check that middle element is NA
7343 bool has_na = idx.array().is_na(1);
7344 passed = passed && has_na;
7345 if (!passed) {
7346 std::cout << " [FAIL] : NA not preserved" << std::endl;
7347 throw std::runtime_error("pd_test_datetime_index_optional_vector_constructor failed");
7348 }
7349
7350 std::cout << " -> tests passed" << std::endl;
7351}
7352
7353void pd_test_datetime_index_copy_constructor() {
arrays (pd_test_1_all.cpp:10642)
10632 std::cout << " -> tests passed" << std::endl;
10633}
10634
10635// ============================================================================
10636// Set Operations Tests
10637// ============================================================================
10638
10639void pd_test_extension_index_append() {
10640 std::cout << "========= append =========================";
10641
10642 // Use same categories for both arrays (required by CategoricalArray::concat)
10643 std::vector<std::string> cats = {"a", "b", "c", "d"};
10644 pandas::CategoricalArray arr1({"a", "b"}, cats);
10645 pandas::CategoricalIndex idx1(arr1);
10646
10647 pandas::CategoricalArray arr2({"c", "d"}, cats);
10648 pandas::CategoricalIndex idx2(arr2);
10649
10650 auto appended = idx1.append(idx2);
10651
10652 bool passed = (appended.size() == 4);
arrays (pd_test_1_all.cpp:10642)
10632 std::cout << " -> tests passed" << std::endl;
10633}
10634
10635// ============================================================================
10636// Set Operations Tests
10637// ============================================================================
10638
10639void pd_test_extension_index_append() {
10640 std::cout << "========= append =========================";
10641
10642 // Use same categories for both arrays (required by CategoricalArray::concat)
10643 std::vector<std::string> cats = {"a", "b", "c", "d"};
10644 pandas::CategoricalArray arr1({"a", "b"}, cats);
10645 pandas::CategoricalIndex idx1(arr1);
10646
10647 pandas::CategoricalArray arr2({"c", "d"}, cats);
10648 pandas::CategoricalIndex idx2(arr2);
10649
10650 auto appended = idx1.append(idx2);
10651
10652 bool passed = (appended.size() == 4);
arrays (pd_test_1_all.cpp:10642)
10632 std::cout << " -> tests passed" << std::endl;
10633}
10634
10635// ============================================================================
10636// Set Operations Tests
10637// ============================================================================
10638
10639void pd_test_extension_index_append() {
10640 std::cout << "========= append =========================";
10641
10642 // Use same categories for both arrays (required by CategoricalArray::concat)
10643 std::vector<std::string> cats = {"a", "b", "c", "d"};
10644 pandas::CategoricalArray arr1({"a", "b"}, cats);
10645 pandas::CategoricalIndex idx1(arr1);
10646
10647 pandas::CategoricalArray arr2({"c", "d"}, cats);
10648 pandas::CategoricalIndex idx2(arr2);
10649
10650 auto appended = idx1.append(idx2);
10651
10652 bool passed = (appended.size() == 4);
axis_must_be_0_or_1_got (pd_test_5_all.cpp:72732)
72722 "axis must be 'index', 'columns', '0', or '1'",
72723 std::string(pandas::error_messages::kAxisMustBeIndexColumnsOrStr01),
72724 local_fail);
72725}
72726
72727void case_3_axis_format_helper(int& local_fail) {
72728 std::cout << "-- case_3_axis_format_helper\n";
72729 check_eq_str(
72730 "case_3.axis_got_2",
72731 "axis must be 0 or 1, got 2",
72732 pandas::error_messages::axis_must_be_0_or_1_got(2),
72733 local_fail);
72734 // Negative value pass-through — `std::to_string(long long)` handles
72735 // negatives uniformly; this guards future replacement with an
72736 // unsigned formatter.
72737 check_eq_str(
72738 "case_3.axis_got_neg7",
72739 "axis must be 0 or 1, got -7",
72740 pandas::error_messages::axis_must_be_0_or_1_got(-7),
72741 local_fail);
72742 // Large-int pass-through.
bdate_range (pd_test_3_all.cpp:1357)
1347 }
1348
1349 std::cout << " -> tests passed" << std::endl;
1350}
1351
1352// ============================================================================
1353// Category 8: DateTime Functions
1354// ============================================================================
1355
1356void pd_test_3_all_bdate_range() {
1357 std::cout << "========= bdate_range() ==============================";
1358
1359 // Create a business date range using start and end dates (not periods)
1360 // This avoids the incomplete periods implementation
1361 pandas::DatetimeIndex result = pandas::bdate_range(
1362 "2024-01-01", // Monday
1363 "2024-01-05", // Friday (5 weekdays: Mon-Fri)
1364 std::nullopt, // Use end date, not periods
1365 "B",
1366 std::nullopt,
1367 true,
build_multiindex_from_string_arrays (pd_test_3_all.cpp:23316)
23306 if (!mi_names[0].has_value() || *mi_names[0] != "first") throw std::runtime_error("wrong name 0");
23307 if (!mi_names[1].has_value() || *mi_names[1] != "second") throw std::runtime_error("wrong name 1");
23308
23309 std::cout << " -> test passed" << std::endl;
23310}
23311
23312void test_build_multiindex_from_arrays() {
23313 std::cout << "========= build_multiindex_from_arrays ================";
23314
23315 std::vector<std::vector<std::string>> arrays = {{"a", "a", "b"}, {"x", "y", "x"}};
23316 pandas::MultiIndex mi = pandas::construct_helpers::build_multiindex_from_string_arrays(arrays);
23317
23318 if (mi.size() != 3) throw std::runtime_error("expected size 3, got " + std::to_string(mi.size()));
23319 if (mi.nlevels() != 2) throw std::runtime_error("expected 2 levels, got " + std::to_string(mi.nlevels()));
23320
23321 auto tup = mi.get_tuple_str(1);
23322 if (tup[0] != "a" || tup[1] != "y") throw std::runtime_error("wrong tuple at index 1");
23323
23324 std::cout << " -> test passed" << std::endl;
23325}
cannot_astype_convert (pd_test_5_all.cpp:74129)
74119 static_assert(
74120 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype(std::string{})),
74121 std::string>,
74122 "unsupported_dtype must return std::string");
74123 static_assert(
74124 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_quoted(std::string{},
74125 std::string{})),
74126 std::string>,
74127 "unsupported_dtype_quoted must return std::string");
74128 static_assert(
74129 std::is_same_v<decltype(pandas::error_messages::cannot_astype_convert(std::string{},
74130 std::string{})),
74131 std::string>,
74132 "cannot_astype_convert must return std::string");
74133 static_assert(
74134 std::is_same_v<decltype(pandas::error_messages::cannot_convert_index_to_dtype(std::string{},
74135 std::string{})),
74136 std::string>,
74137 "cannot_convert_index_to_dtype must return std::string");
74138 static_assert(
74139 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_for_multiindex(std::string{})),
cannot_cast (pd_test_5_all.cpp:72236)
72226 check_eq_str(
72227 "case_3.cat5_TypeError.unsupported_op",
72228 "unsupported operand type for +: 'object'",
72229 pandas::error_messages::unsupported_op("+", "object"),
72230 local_fail);
72231
72232 // Category 6: dtype — cannot cast.
72233 check_eq_str(
72234 "case_3.cat6_dtype.cannot_cast",
72235 "Cannot cast float64 to int64",
72236 pandas::error_messages::cannot_cast("float64", "int64"),
72237 local_fail);
72238
72239 // Category 7: UndefinedVariableError (eval/query).
72240 check_eq_str(
72241 "case_3.cat7_UndefinedVariable.undefined_variable",
72242 "name 'x' is not defined",
72243 pandas::error_messages::undefined_variable("x"),
72244 local_fail);
72245
72246 // Category 8: UnsortedIndexError — MultiIndex lexsort.
cannot_coerce_index (pd_test_5_all.cpp:88527)
88517 pandas::RangeIndex ri(0, 5, 1);
88518 auto v = pandas::coerce_to_vector<double>(
88519 static_cast<const pandas::IndexBase&>(ri));
88520 bool ok = (v.size() == 5) && (v[0] == 0.0) && (v[1] == 1.0) &&
88521 (v[2] == 2.0) && (v[3] == 3.0) && (v[4] == 4.0);
88522 pandas_tests::check(ok, "case_27_rangeindex_to_double()", local_fail);
88523}
88524
88525void case_28_error_message_byte_exact(int& local_fail) {
88526 std::cout << "-- case_28_error_message_byte_exact\n";
88527 std::string got = pandas::error_messages::cannot_coerce_index(
88528 "Index<string>", "int64_t");
88529 std::string expected = "Cannot coerce Index<string> to vector<int64_t>";
88530 bool ok = (got == expected);
88531 pandas_tests::check(ok, "case_28_error_message_byte_exact()", local_fail);
88532 if (!ok) std::cout << " expected=[" << expected << "] got=[" << got
88533 << "]\n";
88534}
88535
88536void case_29_error_message_different_kinds(int& local_fail) {
88537 std::cout << "-- case_29_error_message_different_kinds\n";
cannot_compare_types (pd_test_5_all.cpp:74699)
74689 // Format helpers exist and return std::string.
74690 static_assert(
74691 std::is_same_v<decltype(pandas::error_messages::numeric_only_false(std::string{})),
74692 std::string>,
74693 "numeric_only_false must return std::string");
74694 static_assert(
74695 std::is_same_v<decltype(pandas::error_messages::numeric_only_false_sum_hint(std::string{})),
74696 std::string>,
74697 "numeric_only_false_sum_hint must return std::string");
74698 static_assert(
74699 std::is_same_v<decltype(pandas::error_messages::cannot_compare_types(std::string{},
74700 std::string{})),
74701 std::string>,
74702 "cannot_compare_types must return std::string");
74703 static_assert(
74704 std::is_same_v<decltype(pandas::error_messages::unsupported_binop(std::string{},
74705 std::string{},
74706 std::string{})),
74707 std::string>,
74708 "unsupported_binop must return std::string");
cannot_convert_index_to_dtype (pd_test_5_all.cpp:74134)
74124 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_quoted(std::string{},
74125 std::string{})),
74126 std::string>,
74127 "unsupported_dtype_quoted must return std::string");
74128 static_assert(
74129 std::is_same_v<decltype(pandas::error_messages::cannot_astype_convert(std::string{},
74130 std::string{})),
74131 std::string>,
74132 "cannot_astype_convert must return std::string");
74133 static_assert(
74134 std::is_same_v<decltype(pandas::error_messages::cannot_convert_index_to_dtype(std::string{},
74135 std::string{})),
74136 std::string>,
74137 "cannot_convert_index_to_dtype must return std::string");
74138 static_assert(
74139 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_for_multiindex(std::string{})),
74140 std::string>,
74141 "unsupported_dtype_for_multiindex must return std::string");
74142 static_assert(
74143 std::is_same_v<decltype(pandas::error_messages::cannot_convert_value_in_column(
74144 std::string{}, std::string{}, std::string{}, std::size_t{0}, std::string{})),
cannot_convert_value_in_column (pd_test_5_all.cpp:74143)
74133 static_assert(
74134 std::is_same_v<decltype(pandas::error_messages::cannot_convert_index_to_dtype(std::string{},
74135 std::string{})),
74136 std::string>,
74137 "cannot_convert_index_to_dtype must return std::string");
74138 static_assert(
74139 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_for_multiindex(std::string{})),
74140 std::string>,
74141 "unsupported_dtype_for_multiindex must return std::string");
74142 static_assert(
74143 std::is_same_v<decltype(pandas::error_messages::cannot_convert_value_in_column(
74144 std::string{}, std::string{}, std::string{}, std::size_t{0}, std::string{})),
74145 std::string>,
74146 "cannot_convert_value_in_column must return std::string");
74147
74148 pandas_tests::check(true, "case_1.cat6_constants_and_helpers_type_pinned",
74149 local_fail);
74150}
74151
74152void case_2_byte_exact_wording(int& local_fail) {
74153 std::cout << "-- case_2_byte_exact_wording\n";
canonical_dtype_name (pd_test_5_all.cpp:86367)
86357void case_1_series_complex_dtype_name(int& local_fail) {
86358 std::cout << "-- case_1_series_complex_dtype_name\n";
86359 pandas::Series<cdouble> s({cdouble(1.0, 2.0), cdouble(3.0, 4.0)});
86360 const std::string dt = s.dtype_name();
86361 pandas_tests::check(dt == "complex128",
86362 "case_1_series_complex_dtype_name.dtype_is_complex128_got_" + dt, local_fail);
86363}
86364
86365void case_2_series_canonical_dtype_name(int& local_fail) {
86366 std::cout << "-- case_2_series_canonical_dtype_name\n";
86367 const std::string canon = pandas::Series<cdouble>::canonical_dtype_name();
86368 pandas_tests::check(canon == "complex128",
86369 "case_2_canonical_dtype_name_is_complex128_got_" + canon, local_fail);
86370}
86371
86372void case_3_empty_series_complex_dtype(int& local_fail) {
86373 std::cout << "-- case_3_empty_series_complex_dtype\n";
86374 pandas::Series<cdouble> s(std::vector<cdouble>{});
86375 const std::string dt = s.dtype_name();
86376 pandas_tests::check(dt == "complex128",
86377 "case_3_empty_series_complex_dtype.dtype_is_complex128_got_" + dt, local_fail);
canonicalise_axis (pd_test_5_all.cpp:92263)
92253 "case_12_cond_series_broadcast_other_callable.ncols_eq_3",
92254 local_fail);
92255 pandas_tests::check(!result.to_string().empty(),
92256 "case_12_cond_series_broadcast_other_callable.to_string_nonempty",
92257 local_fail);
92258}
92259
92260void case_13_canonicalise_axis_string_index() {
92261 std::cout << "-- case_13_canonicalise_axis_string_index\n";
92262 int local_fail = 0;
92263 int got = pandas::canonicalise_axis(std::string("index"));
92264 pandas_tests::check(got == 0,
92265 "case_13_canonicalise_axis_string_index.eq_0", local_fail);
92266 // Sanity: distinct invocation should be stable.
92267 int got2 = pandas::canonicalise_axis(std::string("index"));
92268 pandas_tests::check(got2 == 0,
92269 "case_13_canonicalise_axis_string_index.stable_eq_0", local_fail);
92270 pandas_tests::check(got == got2,
92271 "case_13_canonicalise_axis_string_index.idempotent", local_fail);
92272}
canonicalise_axis (pd_test_5_all.cpp:92263)
92253 "case_12_cond_series_broadcast_other_callable.ncols_eq_3",
92254 local_fail);
92255 pandas_tests::check(!result.to_string().empty(),
92256 "case_12_cond_series_broadcast_other_callable.to_string_nonempty",
92257 local_fail);
92258}
92259
92260void case_13_canonicalise_axis_string_index() {
92261 std::cout << "-- case_13_canonicalise_axis_string_index\n";
92262 int local_fail = 0;
92263 int got = pandas::canonicalise_axis(std::string("index"));
92264 pandas_tests::check(got == 0,
92265 "case_13_canonicalise_axis_string_index.eq_0", local_fail);
92266 // Sanity: distinct invocation should be stable.
92267 int got2 = pandas::canonicalise_axis(std::string("index"));
92268 pandas_tests::check(got2 == 0,
92269 "case_13_canonicalise_axis_string_index.stable_eq_0", local_fail);
92270 pandas_tests::check(got == got2,
92271 "case_13_canonicalise_axis_string_index.idempotent", local_fail);
92272}
canonicalize_dtype_for_promote (pd_test_5_all.cpp:144807)
144797 << "] got=[" << out << "]\n";
144798 }
144799}
144800
144801static void expect_canon(const std::string& tag,
144802 std::string_view src,
144803 const std::string& expected,
144804 int& local_fail) {
144805 std::string out;
144806 try {
144807 out = pandas::detail::canonicalize_dtype_for_promote(src);
144808 } catch (const std::exception& e) {
144809 std::cout << " exception: " << e.what() << "\n";
144810 out = "<exc>";
144811 }
144812 bool ok = (out == expected);
144813 pandas_tests::check(ok, "canonicalize_" + tag + "()", local_fail);
144814 if (!ok) {
144815 std::cout << " src=[" << src << "] expected=[" << expected
144816 << "] got=[" << out << "]\n";
144817 }
categorical_categories_dtype_from_np_dtype (pd_test_5_all.cpp:102945)
102935// --- f_test_C_26g_categorical_helpers_9.cpp ---
102936
102937namespace f_test_C_26g_categorical_helpers_9_ns {
102938
102939static void expect_categories_dtype(const std::string& label,
102940 std::string_view input_np_dtype,
102941 const std::string& expected,
102942 int& local_fail) {
102943 std::cout << "-- " << label << "\n";
102944 std::string got = pandas::detail::categorical_categories_dtype_from_np_dtype(input_np_dtype);
102945 pandas_tests::check(got == expected,
102946 label + "()_value", local_fail);
102947 if (got != expected) {
102948 std::cout << " got=[" << got << "] expected=[" << expected << "]\n";
102949 }
102950}
102951
102952static void expect_value_to_str_some(const std::string& label,
102953 const pandas::CoreValueKind& v,
102954 const std::string& expected,
cell_to_dtype_kind (pd_test_5_all.cpp:93104)
93094void case_1_of_float(int& local_fail) {
93095 std::cout << "-- case_1_of_float\n";
93096 pandas::ApplyCellResult r = pandas::ApplyCellResult::of_float(3.14);
93097 pandas_tests::check(r.kind == pandas::ApplyCellResult::Kind::Float,
93098 "C_26_apply_cell_result_case_1_of_float()_kind",
93099 local_fail);
93100 pandas_tests::check(r.flt == 3.14,
93101 "C_26_apply_cell_result_case_1_of_float()_payload",
93102 local_fail);
93103 char k = pandas::cell_to_dtype_kind(r);
93104 pandas_tests::check(k == 'f',
93105 "C_26_apply_cell_result_case_1_of_float()_dtype_kind",
93106 local_fail);
93107 if (k != 'f') std::cout << " got=[" << k << "] expected=[f]\n";
93108}
93109
93110void case_2_of_int(int& local_fail) {
93111 std::cout << "-- case_2_of_int\n";
93112 pandas::ApplyCellResult r = pandas::ApplyCellResult::of_int(
93113 static_cast<int64_t>(42));
classify_dtype (pd_test_5_all.cpp:87626)
87616// --- f_test_06_dtype_string_canonicalize_9.cpp ---
87617
87618namespace f_test_06_dtype_string_canonicalize_9_ns {
87619
87620static void check_classify(const std::string& label,
87621 const std::string& input,
87622 pandas::DTypeCategory expected_cat,
87623 const std::string& expected_p1,
87624 const std::string& expected_p2,
87625 int& local_fail) {
87626 pandas::DTypeInfo info = pandas::classify_dtype(input);
87627 bool ok = (info.cat == expected_cat) &&
87628 (info.param1 == expected_p1) &&
87629 (info.param2 == expected_p2);
87630 pandas_tests::check(ok, label, local_fail);
87631 if (!ok) {
87632 std::cout << " input = [" << input << "]\n"
87633 << " expected = (cat=" << static_cast<int>(expected_cat)
87634 << ", p1=[" << expected_p1 << "]"
87635 << ", p2=[" << expected_p2 << "])\n"
87636 << " actual = (cat=" << static_cast<int>(info.cat)
classify_value_dtype (pd_test_3_all.cpp:25475)
25465 return dataframe_tests_dst_offset::pd_test_dst_timezone_main();
25466}
25467// ------------------- pd_test_dst_timezone (end) ------------------
25468
25469// ------------------- pd_test_value_classify (start) ------------------
25470#include "../pandas/pd_value_classify.h"
25471
25472namespace dataframe_tests_value_classify {
25473
25474void pd_test_value_classify_dtype() {
25475 std::cout << "========= classify_value_dtype() =======================";
25476
25477 auto r1 = pandas::classify_value_dtype("datetime64[ns, US/Eastern]");
25478 if (r1.kind != pandas::ValueKind::DatetimeTZ || r1.tz != "US/Eastern")
25479 throw std::runtime_error("classify_value_dtype failed: DatetimeTZ");
25480 auto r2 = pandas::classify_value_dtype("datetime64[ns]");
25481 if (r2.kind != pandas::ValueKind::DatetimeNaive)
25482 throw std::runtime_error("classify_value_dtype failed: DatetimeNaive");
25483 auto r3 = pandas::classify_value_dtype("timedelta64[ns]");
25484 if (r3.kind != pandas::ValueKind::Timedelta)
25485 throw std::runtime_error("classify_value_dtype failed: Timedelta");
clear_cache (pd_test_1_all.cpp:19413)
19403 s.mean();
19404 s.min();
19405 s.max();
19406
19407 passed = s.has_cached_values() == true;
19408 if (!passed) {
19409 std::cout << " [FAIL] : in pd_test_series_cache() : cache not populated" << std::endl;
19410 throw std::runtime_error("pd_test_series_cache failed: cache not populated");
19411 }
19412
19413 s.clear_cache();
19414 passed = s.has_cached_values() == false;
19415 if (!passed) {
19416 std::cout << " [FAIL] : in pd_test_series_cache() : cache not cleared" << std::endl;
19417 throw std::runtime_error("pd_test_series_cache failed: cache not cleared");
19418 }
19419
19420 std::cout << " -> tests passed" << std::endl;
19421 }
19422
19423 void pd_test_series_string_repr() {
col_data (pd_test_4_all.cpp:5286)
5276namespace {
5277
5278// Build a DataFrame matching the original fixture *after* the sliced setitem.
5279// override_fn(orig) computes the replacement value for every row whose
5280// C-level (third level of the row MultiIndex) is "C1" or "C3".
5281template <typename Fn>
5282pandas::DataFrame build_slicer_post_state(Fn override_fn) {
5283 constexpr size_t N_ROWS = 64; // 4 * 2 * 4 * 2
5284 constexpr size_t N_COLS = 4;
5285
5286 std::vector<std::vector<int64_t>> col_data(N_COLS);
5287 for (auto& v : col_data) v.reserve(N_ROWS);
5288
5289 for (size_t r = 0; r < N_ROWS; ++r) {
5290 // r decomposes as a*16 + b*8 + c*2 + d (strides for 4·2·4·2)
5291 size_t c_lvl = (r / 2) % 4; // 0..3 → C0..C3
5292 bool overridden = (c_lvl == 1 || c_lvl == 3);
5293 for (size_t c = 0; c < N_COLS; ++c) {
5294 int64_t orig = static_cast<int64_t>(r * N_COLS + c);
5295 col_data[c].push_back(overridden ? override_fn(orig) : orig);
5296 }
col_data (pd_test_4_all.cpp:5286)
5276namespace {
5277
5278// Build a DataFrame matching the original fixture *after* the sliced setitem.
5279// override_fn(orig) computes the replacement value for every row whose
5280// C-level (third level of the row MultiIndex) is "C1" or "C3".
5281template <typename Fn>
5282pandas::DataFrame build_slicer_post_state(Fn override_fn) {
5283 constexpr size_t N_ROWS = 64; // 4 * 2 * 4 * 2
5284 constexpr size_t N_COLS = 4;
5285
5286 std::vector<std::vector<int64_t>> col_data(N_COLS);
5287 for (auto& v : col_data) v.reserve(N_ROWS);
5288
5289 for (size_t r = 0; r < N_ROWS; ++r) {
5290 // r decomposes as a*16 + b*8 + c*2 + d (strides for 4·2·4·2)
5291 size_t c_lvl = (r / 2) % 4; // 0..3 → C0..C3
5292 bool overridden = (c_lvl == 1 || c_lvl == 3);
5293 for (size_t c = 0; c < N_COLS; ++c) {
5294 int64_t orig = static_cast<int64_t>(r * N_COLS + c);
5295 col_data[c].push_back(overridden ? override_fn(orig) : orig);
5296 }
collect_index_union (pd_test_3_all.cpp:23100)
23090 std::cout << "========= collect_index_union basic ===================";
23091
23092 // Build two Index<string> with overlapping labels: ["a","b","c"] + ["b","c","d"]
23093 pandas::Index<std::string> idx1(std::vector<std::string>{"a", "b", "c"});
23094 pandas::Index<std::string> idx2(std::vector<std::string>{"b", "c", "d"});
23095
23096 std::vector<pandas::construct::SeriesInfo> infos = {
23097 {3, &idx1, false},
23098 {3, &idx2, false}
23099 };
23100 auto result = pandas::construct::collect_index_union(infos);
23101
23102 if (result.union_index.size() != 4)
23103 throw std::runtime_error("test_collect_union_basic: expected 4 labels, got " +
23104 std::to_string(result.union_index.size()));
23105 std::vector<std::string> expected = {"a", "b", "c", "d"};
23106 if (result.union_index != expected)
23107 throw std::runtime_error("test_collect_union_basic: wrong union labels");
23108 if (!result.has_series_with_index)
23109 throw std::runtime_error("test_collect_union_basic: has_series_with_index should be true");
23110 if (result.max_len != 3)
columns (pd_test_1_all.cpp:6220)
6210 throw std::runtime_error("pd_test_dataframe_properties failed: should be empty");
6211 }
6212
6213 // Test nbytes > 0 for non-empty
6214 if (df.nbytes() == 0) {
6215 std::cout << " [FAIL] : in pd_test_dataframe_properties() : nbytes should be > 0" << std::endl;
6216 throw std::runtime_error("pd_test_dataframe_properties failed: nbytes should be > 0");
6217 }
6218
6219 // Test columns index
6220 if (df.columns().size() != 3) {
6221 std::cout << " [FAIL] : in pd_test_dataframe_properties() : columns size != 3" << std::endl;
6222 throw std::runtime_error("pd_test_dataframe_properties failed: columns size != 3");
6223 }
6224
6225 // Test dtypes
6226 auto dtypes = df.dtypes();
6227 if (dtypes.size() != 3) {
6228 std::cout << " [FAIL] : in pd_test_dataframe_properties() : dtypes size != 3" << std::endl;
6229 throw std::runtime_error("pd_test_dataframe_properties failed: dtypes size != 3");
6230 }
columns (pd_test_1_all.cpp:6220)
6210 throw std::runtime_error("pd_test_dataframe_properties failed: should be empty");
6211 }
6212
6213 // Test nbytes > 0 for non-empty
6214 if (df.nbytes() == 0) {
6215 std::cout << " [FAIL] : in pd_test_dataframe_properties() : nbytes should be > 0" << std::endl;
6216 throw std::runtime_error("pd_test_dataframe_properties failed: nbytes should be > 0");
6217 }
6218
6219 // Test columns index
6220 if (df.columns().size() != 3) {
6221 std::cout << " [FAIL] : in pd_test_dataframe_properties() : columns size != 3" << std::endl;
6222 throw std::runtime_error("pd_test_dataframe_properties failed: columns size != 3");
6223 }
6224
6225 // Test dtypes
6226 auto dtypes = df.dtypes();
6227 if (dtypes.size() != 3) {
6228 std::cout << " [FAIL] : in pd_test_dataframe_properties() : dtypes size != 3" << std::endl;
6229 throw std::runtime_error("pd_test_dataframe_properties failed: dtypes size != 3");
6230 }
compose_override (pd_test_5_all.cpp:93541)
93531void case_23_is_object_bool_false_for_object_int(int& local_fail) {
93532 std::cout << "-- case_23_is_object_bool_false_for_object_int\n";
93533 bool got = pandas::is_object_bool(std::string_view("object:int"));
93534 pandas_tests::check(got == false,
93535 "C_26_dtype_override_case_23_is_object_bool_false_for_object_int()_false",
93536 local_fail);
93537}
93538
93539void case_24_compose_object_bool_first(int& local_fail) {
93540 std::cout << "-- case_24_compose_object_bool_first\n";
93541 std::string got = pandas::compose_override(
93542 std::string_view("object:bool"),
93543 std::string_view("first"),
93544 std::string_view("bool"));
93545 bool ok = (got == "object");
93546 pandas_tests::check(ok,
93547 "C_26_dtype_override_case_24_compose_object_bool_first()_value",
93548 local_fail);
93549 if (!ok) std::cout << " got=[" << got << "] expected=[object]\n";
93550}
current (pd_test_4_all.cpp:1140)
1130 const std::string& actual) {
1131 int _f = 0;
1132 pandas_tests::check_str_ws(label, expected, actual, _f);
1133 if (_f > 0) throw std::runtime_error(label + ": str mismatch");
1134}
1135
1136// ----------------------------------------------------------------------------
1137// Case 1 — dtype.int32_df_nsmallest
1138// ----------------------------------------------------------------------------
1139void dtype_int32_df_nsmallest() {
1140 // Strategy B: synthesize the current (buggy) post-nsmallest state.
1141 // Column A is double because int32 is silently promoted inside
1142 // pandas::DataFrame::nsmallest today. Column B (from range(10)) stays
1143 // int64. Row index labels "2","6","4" are the original positions of the
1144 // 3 smallest A values, ties broken by first-occurrence.
1145 pandas::DataFrame df;
1146 df.add_column<double>("A", std::vector<double>{1.0, 2.0, 3.0});
1147 df.add_column<int64_t>("B", std::vector<int64_t>{2, 6, 4});
1148 df.set_index(std::make_unique<pandas::Index<std::string>>(
1149 std::vector<std::string>{"2", "6", "4"}));
1150 apply_default_display(df);
cut (pd_test_3_all.cpp:13483)
13473 }
13474
13475 std::cout << " -> tests passed" << std::endl;
13476}
13477
13478// ============================================================================
13479// Cut and Qcut Tests
13480// ============================================================================
13481
13482void pd_test_top_level_cut() {
13483 std::cout << "========= cut() =======================================";
13484
13485 std::vector<double> x = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
13486
13487 // Test cut with number of bins
13488 pandas::CutResult<double> result = pandas::cut<double>(x, 4);
13489 if (result.bins.size() != 4) {
13490 std::cout << " [FAIL] : in pd_test_top_level_cut() : expected 4 bins, got " << result.bins.size() << std::endl;
13491 throw std::runtime_error("pd_test_top_level_cut failed: wrong bin count");
13492 }
13493 if (result.labels.size() != 4) {
date_range (pd_test_1_all.cpp:7908)
7898 }
7899
7900 std::cout << " -> tests passed" << std::endl;
7901}
7902
7903// ============================================================================
7904// Factory Function Tests
7905// ============================================================================
7906
7907void pd_test_datetime_index_date_range_start_end() {
7908 std::cout << "========= date_range (start, end) =====================";
7909
7910 auto idx = pandas::date_range("2020-01-01", "2020-01-10");
7911
7912 bool passed = (idx.size() == 10);
7913 if (!passed) {
7914 std::cout << " [FAIL] : expected 10 elements, got " << idx.size() << std::endl;
7915 throw std::runtime_error("pd_test_datetime_index_date_range_start_end failed");
7916 }
7917
7918 std::cout << " -> tests passed" << std::endl;
date_range (pd_test_1_all.cpp:7908)
7898 }
7899
7900 std::cout << " -> tests passed" << std::endl;
7901}
7902
7903// ============================================================================
7904// Factory Function Tests
7905// ============================================================================
7906
7907void pd_test_datetime_index_date_range_start_end() {
7908 std::cout << "========= date_range (start, end) =====================";
7909
7910 auto idx = pandas::date_range("2020-01-01", "2020-01-10");
7911
7912 bool passed = (idx.size() == 10);
7913 if (!passed) {
7914 std::cout << " [FAIL] : expected 10 elements, got " << idx.size() << std::endl;
7915 throw std::runtime_error("pd_test_datetime_index_date_range_start_end failed");
7916 }
7917
7918 std::cout << " -> tests passed" << std::endl;
date_range_with_offset (pd_test_3_all.cpp:24739)
24729int pd_test_rolling_time_main() {
24730 return dataframe_tests_rolling_time::pd_test_rolling_time_main();
24731}
24732// ------------------- pd_test_rolling_time (end) ---------------------------
24733
24734// ------------------- pd_test_date_range_offset (start) ---------------------------
24735namespace dataframe_tests_date_range_offset {
24736
24737void pd_test_date_range_offset_with_periods() {
24738 std::cout << "========= date_range_with_offset (periods) =======================";
24739 // BusinessDay(1) from 2024-01-01 (Mon) with periods=5 => Mon-Fri
24740 pandas::BusinessDay bday(1);
24741 auto dti = pandas::date_range_with_offset(
24742 bday, "2024-01-01", std::nullopt, std::optional<size_t>(5));
24743 if (dti.size() != 5)
24744 throw std::runtime_error("expected 5 dates, got " + std::to_string(dti.size()));
24745 // Verify all 5 are weekdays Mon(0)-Fri(4)
24746 for (size_t i = 0; i < dti.size(); ++i) {
24747 auto val = dti.array()[i];
24748 if (!val.has_value())
datetime64_to_ns (pd_test_3_all.cpp:22775)
22765 throw std::runtime_error("test_time_unit_factor: Day factor wrong");
22766
22767 std::cout << " -> test passed" << std::endl;
22768}
22769
22770void test_datetime64_to_ns() {
22771 std::cout << " test_datetime64_to_ns" << std::endl;
22772
22773 // 5 microseconds = 5000 nanoseconds
22774 numpy::datetime64 dt_us(5, numpy::DateTimeUnit::Microsecond);
22775 int64_t ns_us = pandas::construct_helpers::datetime64_to_ns(dt_us);
22776 if (ns_us != 5000LL)
22777 throw std::runtime_error("test_datetime64_to_ns: 5 us should be 5000 ns, got " + std::to_string(ns_us));
22778
22779 // 1 second = 1e9 nanoseconds
22780 numpy::datetime64 dt_s(1, numpy::DateTimeUnit::Second);
22781 int64_t ns_s = pandas::construct_helpers::datetime64_to_ns(dt_s);
22782 if (ns_s != 1000000000LL)
22783 throw std::runtime_error("test_datetime64_to_ns: 1 s should be 1e9 ns, got " + std::to_string(ns_s));
22784
22785 // 2 nanoseconds = 2 nanoseconds (identity)
datetime_unit_to_ns_multiplier (pd_test_2_all.cpp:22559)
22549 ++g_fail;
22550 }
22551}
22552
22553// =====================================================================
22554// Unit multiplier tests
22555// =====================================================================
22556
22557void test_datetime_unit_ns_multiplier() {
22558 std::cout << " -- test_datetime_unit_ns_multiplier --" << std::endl;
22559 check(pandas::datetime_unit_to_ns_multiplier("ns") == 1, "ns");
22560 check(pandas::datetime_unit_to_ns_multiplier("nanoseconds") == 1, "nanoseconds");
22561 check(pandas::datetime_unit_to_ns_multiplier("us") == 1000, "us");
22562 check(pandas::datetime_unit_to_ns_multiplier("microseconds") == 1000, "microseconds");
22563 check(pandas::datetime_unit_to_ns_multiplier("ms") == 1000000, "ms");
22564 check(pandas::datetime_unit_to_ns_multiplier("milliseconds") == 1000000, "milliseconds");
22565 check(pandas::datetime_unit_to_ns_multiplier("s") == 1000000000LL, "s");
22566 check(pandas::datetime_unit_to_ns_multiplier("seconds") == 1000000000LL, "seconds");
22567 check(pandas::datetime_unit_to_ns_multiplier("sec") == 1000000000LL, "sec");
22568 check(pandas::datetime_unit_to_ns_multiplier("m") == 60LL * 1000000000LL, "m");
22569 check(pandas::datetime_unit_to_ns_multiplier("min") == 60LL * 1000000000LL, "min");
day_of_week (pd_test_3_all.cpp:22018)
22008void test_dt_aliases() {
22009 std::cout << "========= dt accessor aliases ====================";
22010
22011 std::vector<numpy::datetime64> dates = {
22012 numpy::datetime64("2023-01-15"),
22013 numpy::datetime64("2023-06-20")
22014 };
22015 pandas::Series<numpy::datetime64> s(dates);
22016
22017 auto dow1 = s.dt().dayofweek();
22018 auto dow2 = s.dt().day_of_week();
22019 auto dow3 = s.dt().weekday();
22020
22021 if (dow1[0] != dow2[0] || dow1[0] != dow3[0]) {
22022 throw std::runtime_error("dt aliases: dayofweek/day_of_week/weekday mismatch");
22023 }
22024
22025 auto doy1 = s.dt().dayofyear();
22026 auto doy2 = s.dt().day_of_year();
22027
22028 if (doy1[0] != doy2[0]) {
days_in_month (pd_test_1_all.cpp:2766)
2756 std::cout << " [FAIL] : day[0] should be 15" << std::endl;
2757 throw std::runtime_error("pd_test_period_array_day_components failed: day[0]");
2758 }
2759 auto d1 = days[1];
2760 if (!d1.has_value() || d1.value() != 25) {
2761 std::cout << " [FAIL] : day[1] should be 25" << std::endl;
2762 throw std::runtime_error("pd_test_period_array_day_components failed: day[1]");
2763 }
2764
2765 // Days in month
2766 auto dim = arr.days_in_month();
2767 auto dim0 = dim[0];
2768 if (!dim0.has_value() || dim0.value() != 31) {
2769 std::cout << " [FAIL] : days_in_month[0] should be 31 (March)" << std::endl;
2770 throw std::runtime_error("pd_test_period_array_day_components failed: days_in_month[0]");
2771 }
2772 auto dim1 = dim[1];
2773 if (!dim1.has_value() || dim1.value() != 31) {
2774 std::cout << " [FAIL] : days_in_month[1] should be 31 (December)" << std::endl;
2775 throw std::runtime_error("pd_test_period_array_day_components failed: days_in_month[1]");
2776 }
days_in_month (pd_test_1_all.cpp:2766)
2756 std::cout << " [FAIL] : day[0] should be 15" << std::endl;
2757 throw std::runtime_error("pd_test_period_array_day_components failed: day[0]");
2758 }
2759 auto d1 = days[1];
2760 if (!d1.has_value() || d1.value() != 25) {
2761 std::cout << " [FAIL] : day[1] should be 25" << std::endl;
2762 throw std::runtime_error("pd_test_period_array_day_components failed: day[1]");
2763 }
2764
2765 // Days in month
2766 auto dim = arr.days_in_month();
2767 auto dim0 = dim[0];
2768 if (!dim0.has_value() || dim0.value() != 31) {
2769 std::cout << " [FAIL] : days_in_month[0] should be 31 (March)" << std::endl;
2770 throw std::runtime_error("pd_test_period_array_day_components failed: days_in_month[0]");
2771 }
2772 auto dim1 = dim[1];
2773 if (!dim1.has_value() || dim1.value() != 31) {
2774 std::cout << " [FAIL] : days_in_month[1] should be 31 (December)" << std::endl;
2775 throw std::runtime_error("pd_test_period_array_day_components failed: days_in_month[1]");
2776 }
detect_int_columns (pd_test_3_all.cpp:22937)
22927 col4.name = "D";
22928 col4.string_data = {"x", "y"};
22929 col4.is_numeric = false;
22930
22931 // Empty numeric -> is_int = false
22932 pandas::construct_helpers::RecordColumn col5;
22933 col5.name = "E";
22934 col5.is_numeric = true;
22935
22936 std::vector<pandas::construct_helpers::RecordColumn> cols = {col1, col2, col3, col4, col5};
22937 pandas::construct_helpers::detect_int_columns(cols);
22938
22939 if (!cols[0].is_int)
22940 throw std::runtime_error("test_detect_int_columns: [1.0,2.0,3.0] should be is_int=true");
22941 if (cols[1].is_int)
22942 throw std::runtime_error("test_detect_int_columns: [1.5,2.0,3.0] should be is_int=false");
22943 if (cols[2].is_int)
22944 throw std::runtime_error("test_detect_int_columns: [1.0,NaN] should be is_int=false");
22945 if (cols[3].is_int)
22946 throw std::runtime_error("test_detect_int_columns: string col should be is_int=false");
22947 if (cols[4].is_int)
detect_tuple_key_levels (pd_test_3_all.cpp:22998)
22988 throw std::runtime_error("test_records_to_dataframe: column Y should not have int64 override");
22989
22990 std::cout << " -> test passed" << std::endl;
22991}
22992
22993void test_detect_tuple_keys() {
22994 std::cout << "========= detect_tuple_key_levels ====================";
22995
22996 // All 2-tuples -> {true, 2}
22997 std::vector<std::pair<bool, size_t>> keys1 = {{true, 2}, {true, 2}, {true, 2}};
22998 auto info1 = pandas::construct_helpers::detect_tuple_key_levels(keys1);
22999 if (!info1.all_tuple_keys || info1.tuple_len != 2)
23000 throw std::runtime_error("test_detect_tuple_keys: all 2-tuples should be {true, 2}");
23001
23002 // Mixed lengths -> {false, 0}
23003 std::vector<std::pair<bool, size_t>> keys2 = {{true, 2}, {true, 3}};
23004 auto info2 = pandas::construct_helpers::detect_tuple_key_levels(keys2);
23005 if (info2.all_tuple_keys || info2.tuple_len != 0)
23006 throw std::runtime_error("test_detect_tuple_keys: mixed lengths should be {false, 0}");
23007
23008 // Non-tuple key -> {false, 0}
detect_tz_uniformity (pd_test_3_all.cpp:27218)
27208 check(std::abs(result[2] - 3.0) < 1e-10, "sqrt(9)==3");
27209 check(result.name() == "data", "name preserved");
27210}
27211
27212// Test 8: detect_tz_uniformity
27213void pd_test_detect_tz_uniformity() {
27214 std::cout << " -- pd_test_detect_tz_uniformity --" << std::endl;
27215 // Uniform case
27216 {
27217 std::vector<std::string> tz_strings = {"UTC", "UTC", "UTC"};
27218 auto [uniform, tz] = ::pandas::detect_tz_uniformity(tz_strings);
27219 check(uniform, "all UTC -> uniform");
27220 check(tz == "UTC", "common tz == UTC");
27221 }
27222 // Non-uniform case
27223 {
27224 std::vector<std::string> tz_strings = {"UTC", "US/Eastern", "UTC"};
27225 auto [uniform, tz] = ::pandas::detect_tz_uniformity(tz_strings);
27226 check(!uniform, "mixed tz -> not uniform");
27227 }
27228 // Empty first entry
dt (pd_test_3_all.cpp:18239)
18229 if (offset.freqstr() != "D") {
18230 std::cout << " [FAIL] : Day freqstr() failed" << std::endl;
18231 throw std::runtime_error("pd_test_day_offset: freqstr() failed");
18232 }
18233 if (offset.name() != "Day") {
18234 std::cout << " [FAIL] : Day name() failed" << std::endl;
18235 throw std::runtime_error("pd_test_day_offset: name() failed");
18236 }
18237
18238 // Test apply
18239 numpy::datetime64 dt("2020-01-15");
18240 auto result = offset.apply(dt);
18241 std::tm tm = result.toTm();
18242 if (tm.tm_mday != 20) {
18243 std::cout << " [FAIL] : Day apply() failed, got day " << tm.tm_mday << std::endl;
18244 throw std::runtime_error("pd_test_day_offset: apply() failed");
18245 }
18246
18247 std::cout << " -> tests passed" << std::endl;
18248}
dt (pd_test_3_all.cpp:18239)
18229 if (offset.freqstr() != "D") {
18230 std::cout << " [FAIL] : Day freqstr() failed" << std::endl;
18231 throw std::runtime_error("pd_test_day_offset: freqstr() failed");
18232 }
18233 if (offset.name() != "Day") {
18234 std::cout << " [FAIL] : Day name() failed" << std::endl;
18235 throw std::runtime_error("pd_test_day_offset: name() failed");
18236 }
18237
18238 // Test apply
18239 numpy::datetime64 dt("2020-01-15");
18240 auto result = offset.apply(dt);
18241 std::tm tm = result.toTm();
18242 if (tm.tm_mday != 20) {
18243 std::cout << " [FAIL] : Day apply() failed, got day " << tm.tm_mday << std::endl;
18244 throw std::runtime_error("pd_test_day_offset: apply() failed");
18245 }
18246
18247 std::cout << " -> tests passed" << std::endl;
18248}
dt_idx (pd_test_1_all.cpp:15618)
15608void pd_test_is_all_dates() {
15609 std::cout << "========= is_all_dates() =========================";
15610
15611 // DatetimeIndex
15612 numpy::NDArray<numpy::datetime64> dt_data(std::vector<size_t>{1});
15613 dt_data.setElementAt({0}, numpy::datetime64(1000LL, numpy::DateTimeUnit::Nanosecond));
15614 numpy::NDArray<numpy::bool_> dt_mask(std::vector<size_t>{1});
15615 dt_mask.setElementAt({0}, numpy::bool_(false));
15616 pandas::DatetimeArray dt_arr(dt_data, dt_mask);
15617 pandas::DatetimeIndexBase dt_idx(dt_arr);
15618
15619 // TimedeltaIndex
15620 numpy::NDArray<numpy::timedelta64> td_data(std::vector<size_t>{1});
15621 td_data.setElementAt({0}, numpy::timedelta64(1000LL, numpy::DateTimeUnit::Nanosecond));
15622 numpy::NDArray<numpy::bool_> td_mask(std::vector<size_t>{1});
15623 td_mask.setElementAt({0}, numpy::bool_(false));
15624 pandas::TimedeltaArray td_arr(td_data, td_mask);
15625 pandas::TimedeltaIndexBase td_idx(td_arr);
15626
15627 // PeriodIndex
dt_idx (pd_test_1_all.cpp:15618)
15608void pd_test_is_all_dates() {
15609 std::cout << "========= is_all_dates() =========================";
15610
15611 // DatetimeIndex
15612 numpy::NDArray<numpy::datetime64> dt_data(std::vector<size_t>{1});
15613 dt_data.setElementAt({0}, numpy::datetime64(1000LL, numpy::DateTimeUnit::Nanosecond));
15614 numpy::NDArray<numpy::bool_> dt_mask(std::vector<size_t>{1});
15615 dt_mask.setElementAt({0}, numpy::bool_(false));
15616 pandas::DatetimeArray dt_arr(dt_data, dt_mask);
15617 pandas::DatetimeIndexBase dt_idx(dt_arr);
15618
15619 // TimedeltaIndex
15620 numpy::NDArray<numpy::timedelta64> td_data(std::vector<size_t>{1});
15621 td_data.setElementAt({0}, numpy::timedelta64(1000LL, numpy::DateTimeUnit::Nanosecond));
15622 numpy::NDArray<numpy::bool_> td_mask(std::vector<size_t>{1});
15623 td_mask.setElementAt({0}, numpy::bool_(false));
15624 pandas::TimedeltaArray td_arr(td_data, td_mask);
15625 pandas::TimedeltaIndexBase td_idx(td_arr);
15626
15627 // PeriodIndex
dtype_category_to_canonical_string (pd_test_5_all.cpp:87650)
87640}
87641
87642static void check_reverse(const std::string& label,
87643 pandas::DTypeCategory cat,
87644 const std::string& p1,
87645 const std::string& p2,
87646 const std::string& expected,
87647 int& local_fail) {
87648 pandas::DTypeInfo info{cat, p1, p2};
87649 std::string actual =
87650 pandas::dtype_category_to_canonical_string(cat, info);
87651 bool ok = (actual == expected);
87652 pandas_tests::check(ok, label, local_fail);
87653 if (!ok) {
87654 std::cout << " cat = " << static_cast<int>(cat)
87655 << " p1=[" << p1 << "] p2=[" << p2 << "]\n"
87656 << " expected = [" << expected << "]\n"
87657 << " actual = [" << actual << "]\n";
87658 }
87659}
ensure_dtype_can_hold_na (pd_test_5_all.cpp:56410)
56400static std::string mp(std::string_view dt, pandas::detail::FillKind k, bool has_missing) {
56401 return pandas::detail::maybe_promote(dt, k, has_missing);
56402}
56403
56404static std::string mp_float(std::string_view dt, double fv) {
56405 return pandas::detail::maybe_promote(dt, pandas::detail::FillKind::Float, true, fv);
56406}
56407
56408static std::string ehd(std::string_view dt) {
56409 return pandas::detail::ensure_dtype_can_hold_na(dt);
56410}
56411
56412void pd_promote_9_413721_case_1_ehd_bool_promotes_to_object(int& local_fail) {
56413 std::cout << "----- case_1_ehd_bool_promotes_to_object -----\n";
56414 check_str("pd_promote.ehd_bool", "object", ehd("bool"), local_fail);
56415 check_str("pd_promote.ehd_object_bool", "object", ehd("object:bool"), local_fail);
56416}
56417
56418void pd_promote_9_413721_case_2_ehd_native_int_promotes_to_float64(int& local_fail) {
56419 std::cout << "----- case_2_ehd_native_int_promotes_to_float64 -----\n";
extract_date_if_midnight (pd_test_3_all.cpp:25167)
25157 std::cout << "========= nanos_to_timestamp_str: pre-epoch 1960 =======";
25158 int64_t ns = pandas::Timestamp::componentsToNanos(1960, 1, 1, 0, 0, 0, 0, 0);
25159 auto result = pandas::datetime_utils::nanos_to_timestamp_str(ns);
25160 if (result != "1960-01-01 00:00:00")
25161 throw std::runtime_error("nanos_to_str pre-epoch: got " + result);
25162 std::cout << " -> tests passed" << std::endl;
25163}
25164
25165void pd_test_datetime_utils_midnight() {
25166 std::cout << "========= extract_date_if_midnight: midnight ===========";
25167 auto r = pandas::datetime_utils::extract_date_if_midnight("2000-01-06 00:00:00");
25168 if (r != "2000-01-06")
25169 throw std::runtime_error("extract_date midnight: got " + r);
25170 std::cout << " -> tests passed" << std::endl;
25171}
25172
25173void pd_test_datetime_utils_midnight_nanos() {
25174 std::cout << "========= extract_date_if_midnight: midnight+nanos =====";
25175 auto r = pandas::datetime_utils::extract_date_if_midnight("2000-01-06 00:00:00.000000000");
25176 if (r != "2000-01-06")
25177 throw std::runtime_error("extract_date midnight nanos: got " + r);
extract_epoch_seconds (pd_test_3_all.cpp:24668)
24658void pd_test_rolling_time_epoch_seconds() {
24659 std::cout << "========= extract_epoch_seconds ====================";
24660 // Create a 3-date DatetimeIndex: 2023-01-01, 2023-01-02, 2023-01-03
24661 std::vector<numpy::datetime64> dates = {
24662 numpy::datetime64("2023-01-01"),
24663 numpy::datetime64("2023-01-02"),
24664 numpy::datetime64("2023-01-03")
24665 };
24666 pandas::DatetimeIndex dti(dates);
24667 auto epochs = pandas::extract_epoch_seconds(dti);
24668 if (epochs.size() != 3)
24669 throw std::runtime_error("expected 3 epoch values");
24670 // Consecutive days should be 86400s apart
24671 if (epochs[1] - epochs[0] != 86400)
24672 throw std::runtime_error("expected 86400s between day 1 and day 2");
24673 if (epochs[2] - epochs[1] != 86400)
24674 throw std::runtime_error("expected 86400s between day 2 and day 3");
24675 std::cout << " -> tests passed" << std::endl;
24676}
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
file (pd_test_2_all.cpp:3463)
3453 {"C", {100, 200, 300, 400, 500}}
3454 };
3455
3456 pandas::DataFrame df(data);
3457
3458 // Export to Excel
3459 std::string filepath = "temp/pd_test_excel_basic.xlsx";
3460 df.to_excel(filepath);
3461
3462 // Verify file was created
3463 std::ifstream file(filepath, std::ios::binary);
3464 if (!file.good()) {
3465 std::cout << " [FAIL] : in pd_test_excel_basic() : File was not created" << std::endl;
3466 throw std::runtime_error("pd_test_excel_basic failed: file not created");
3467 }
3468
3469 // Check file size is reasonable (valid XLSX should be > 1KB)
3470 file.seekg(0, std::ios::end);
3471 auto size = file.tellg();
3472 if (size < 1000) {
3473 std::cout << " [FAIL] : in pd_test_excel_basic() : File size too small: " << size << std::endl;
find_common_type (pd_test_5_all.cpp:39698)
39688}
39689
39690static pandas::DataFrame concat_axis1(const pandas::DataFrame& a,
39691 const pandas::DataFrame& b) {
39692 std::vector<pandas::DataFrame> frames{a, b};
39693 return pandas::concat(frames, /*axis=*/1);
39694}
39695
39696void f_concat_df_bool_int_524871_case_1_helper_bool_int8_object(int& local_fail) {
39697 std::cout << "-- case_1_helper_bool_int8_object\n";
39698 auto got = pandas::detail::find_common_type({"bool", "int8"});
39699 pandas_tests::check(got == "object",
39700 "case_1.find_common_type({bool,int8}) == object (got '" + got + "')",
39701 local_fail);
39702}
39703
39704void f_concat_df_bool_int_524871_case_2_helper_bool_int16_object(int& local_fail) {
39705 std::cout << "-- case_2_helper_bool_int16_object\n";
39706 auto got = pandas::detail::find_common_type({"bool", "int16"});
39707 pandas_tests::check(got == "object",
39708 "case_2.find_common_type({bool,int16}) == object (got '" + got + "')",
flatten_dict (pd_test_5_all.cpp:81031)
81021}
81022
81023// --- f_test_plan_06_normalize_jsonvalue_9.cpp ---
81024
81025namespace f_test_plan_06_normalize_jsonvalue_9_ns {
81026
81027struct PIO {
81028 static std::string json_value_to_string(const pandas::io::JsonValue& v) {
81029 return pandas::io::json_value_to_string(v);
81030 }
81031 static void flatten_dict(const pandas::io::JsonObject& d,
81032 const std::string& prefix,
81033 const std::string& sep,
81034 int max_level,
81035 int level,
81036 std::vector<std::pair<std::string, std::string>>& out) {
81037 pandas::io::flatten_dict(d, prefix, sep, max_level, level, out);
81038 }
81039 static const pandas::io::JsonValue* lookup_path(
81040 const pandas::io::JsonObject& root,
81041 const std::vector<std::string>& path) {
flatten_dict (pd_test_5_all.cpp:81031)
81021}
81022
81023// --- f_test_plan_06_normalize_jsonvalue_9.cpp ---
81024
81025namespace f_test_plan_06_normalize_jsonvalue_9_ns {
81026
81027struct PIO {
81028 static std::string json_value_to_string(const pandas::io::JsonValue& v) {
81029 return pandas::io::json_value_to_string(v);
81030 }
81031 static void flatten_dict(const pandas::io::JsonObject& d,
81032 const std::string& prefix,
81033 const std::string& sep,
81034 int max_level,
81035 int level,
81036 std::vector<std::pair<std::string, std::string>>& out) {
81037 pandas::io::flatten_dict(d, prefix, sep, max_level, level, out);
81038 }
81039 static const pandas::io::JsonValue* lookup_path(
81040 const pandas::io::JsonObject& root,
81041 const std::vector<std::string>& path) {
flatten_dict (pd_test_5_all.cpp:81031)
81021}
81022
81023// --- f_test_plan_06_normalize_jsonvalue_9.cpp ---
81024
81025namespace f_test_plan_06_normalize_jsonvalue_9_ns {
81026
81027struct PIO {
81028 static std::string json_value_to_string(const pandas::io::JsonValue& v) {
81029 return pandas::io::json_value_to_string(v);
81030 }
81031 static void flatten_dict(const pandas::io::JsonObject& d,
81032 const std::string& prefix,
81033 const std::string& sep,
81034 int max_level,
81035 int level,
81036 std::vector<std::pair<std::string, std::string>>& out) {
81037 pandas::io::flatten_dict(d, prefix, sep, max_level, level, out);
81038 }
81039 static const pandas::io::JsonValue* lookup_path(
81040 const pandas::io::JsonObject& root,
81041 const std::vector<std::string>& path) {
format_duplicate_label_error (pd_test_2_all.cpp:21263)
21253// =====================================================================
21254// 7F: Duplicate label error formatter
21255// =====================================================================
21256
21257void test_format_duplicate_label_error() {
21258 std::cout << " -- test_format_duplicate_label_error --" << std::endl;
21259
21260 pandas::Index<std::string> idx({"a", "b", "a", "c", "b"});
21261
21262 std::string msg = pandas::format_duplicate_label_error(idx);
21263
21264 check(msg.find("Index has duplicates.") != std::string::npos, "has_header");
21265 check(msg.find("positions") != std::string::npos, "has_positions_header");
21266 check(msg.find("label") != std::string::npos, "has_label_header");
21267 // "a" appears at positions 0, 2
21268 check(msg.find("[0, 2]") != std::string::npos, "a_positions");
21269 // "b" appears at positions 1, 4
21270 check(msg.find("[1, 4]") != std::string::npos, "b_positions");
21271}
format_float (pd_test_5_all.cpp:57514)
57504 std::vector<double> v = {1.5, 2.25};
57505 int p = pandas::detail::infer_float_repr_precision(std::span<const double>(v));
57506 // Plan 14 Case 27 inverted: helper returns 2 (1.5 -> 1dp, 2.25 -> 2dp,
57507 // max = 2).
57508 pandas_tests::check(p == 2,
57509 "format_helpers_coverage_8b2f47_case_Plan14_27.infer_two_decimals", local_fail);
57510}
57511
57512static void f_format_helpers_coverage_8b2f47_case_B01_nan_prec0(int& local_fail) {
57513 std::cout << "-- case_B01_nan_prec0\n";
57514 std::string s = pandas::detail::format_float(
57515 std::numeric_limits<double>::quiet_NaN(), 0);
57516 pandas_tests::check(s == "NaN",
57517 "format_helpers_coverage_8b2f47_case_B01.NaN_prec0", local_fail);
57518}
57519
57520static void f_format_helpers_coverage_8b2f47_case_B02_nan_prec5(int& local_fail) {
57521 std::cout << "-- case_B02_nan_prec5\n";
57522 std::string s = pandas::detail::format_float(
57523 std::numeric_limits<double>::quiet_NaN(), 5);
57524 pandas_tests::check(s == "NaN",
format_pivot_cell_value (pd_test_2_all.cpp:21231)
21221 check(result.find("X") != std::string::npos, "contains_X");
21222 check(result.find("Y") != std::string::npos, "contains_Y");
21223 check(result.find("row1") != std::string::npos, "contains_row1");
21224 check(result.find("idx") != std::string::npos, "contains_idx");
21225}
21226
21227void test_format_pivot_cell_int() {
21228 std::cout << " -- test_format_pivot_cell_int --" << std::endl;
21229
21230 // sum with integer value -> integer string
21231 check(pandas::display::format_pivot_cell_value(42.0, "42.0", "sum") == "42",
21232 "sum_int");
21233 // count with integer value -> integer string
21234 check(pandas::display::format_pivot_cell_value(7.0, "7.0", "count") == "7",
21235 "count_int");
21236 // min with integer -> integer string
21237 check(pandas::display::format_pivot_cell_value(3.0, "3.0", "min") == "3",
21238 "min_int");
21239 // max with integer -> integer string
21240 check(pandas::display::format_pivot_cell_value(100.0, "100.0", "max") == "100",
21241 "max_int");
format_pivot_multi_aggfunc (pd_test_2_all.cpp:21214)
21204 std::vector<std::string> sub_cols = {"X", "Y"};
21205
21206 // 4 data columns: (sum, X), (sum, Y), (mean, X), (mean, Y)
21207 std::vector<std::vector<std::string>> str_data = {
21208 {"10", "20"}, // sum, X
21209 {"30", "40"}, // sum, Y
21210 {"1.5", "2.5"}, // mean, X
21211 {"3.5", "4.5"} // mean, Y
21212 };
21213
21214 std::string result = pandas::display::format_pivot_multi_aggfunc(
21215 idx_vals, idx_names, col_lvl, aggfuncs, sub_cols, str_data);
21216
21217 // Should produce a non-empty formatted string with hierarchical headers
21218 check(!result.empty(), "result_not_empty");
21219 check(result.find("sum") != std::string::npos, "contains_sum");
21220 check(result.find("mean") != std::string::npos, "contains_mean");
21221 check(result.find("X") != std::string::npos, "contains_X");
21222 check(result.find("Y") != std::string::npos, "contains_Y");
21223 check(result.find("row1") != std::string::npos, "contains_row1");
21224 check(result.find("idx") != std::string::npos, "contains_idx");
format_quantile_label (pd_test_3_all.cpp:25776)
25766int pd_test_display_formats_main() {
25767 return dataframe_tests_display_formats::pd_test_display_formats_main();
25768}
25769// ------------------- pd_test_display_formats (end) -----------------------------
25770
25771// ------------------- pd_test_series_format_helpers (begin) ---------------------
25772namespace dataframe_tests_series_format_helpers {
25773
25774void pd_test_series_format_helpers_quantile_label() {
25775 std::cout << " format_quantile_label... ";
25776 std::string r1 = ::pandas::display::format_quantile_label(0.25);
25777 if (r1 != "0.25") throw std::runtime_error("Expected '0.25', got '" + r1 + "'");
25778 std::string r2 = ::pandas::display::format_quantile_label(0.5);
25779 if (r2 != "0.5") throw std::runtime_error("Expected '0.5', got '" + r2 + "'");
25780 std::string r3 = ::pandas::display::format_quantile_label(0.75);
25781 if (r3 != "0.75") throw std::runtime_error("Expected '0.75', got '" + r3 + "'");
25782 std::cout << "PASSED" << std::endl;
25783}
25784
25785void pd_test_series_format_helpers_quantile_list() {
25786 std::cout << " quantile_list... ";
found (pd_test_2_all.cpp:13553)
13543 // Should have formatted values with 2 decimal places
13544 bool passed = md.find("3.14") != std::string::npos;
13545 if (!passed) {
13546 std::cout << " [FAIL] : in pd_test_to_markdown_float_format() : formatted value not found" << std::endl;
13547 throw std::runtime_error("pd_test_to_markdown_float_format failed");
13548 }
13549
13550 // Should NOT have full precision
13551 passed = md.find("3.14159265") == std::string::npos;
13552 if (!passed) {
13553 std::cout << " [FAIL] : in pd_test_to_markdown_float_format() : full precision found (should be formatted)" << std::endl;
13554 throw std::runtime_error("pd_test_to_markdown_float_format failed");
13555 }
13556
13557 std::cout << " -> tests passed" << std::endl;
13558 }
13559
13560 // Test custom column alignment
13561 void pd_test_to_markdown_colalign() {
13562 std::cout << "========= custom column alignment ===================";
found (pd_test_2_all.cpp:13553)
13543 // Should have formatted values with 2 decimal places
13544 bool passed = md.find("3.14") != std::string::npos;
13545 if (!passed) {
13546 std::cout << " [FAIL] : in pd_test_to_markdown_float_format() : formatted value not found" << std::endl;
13547 throw std::runtime_error("pd_test_to_markdown_float_format failed");
13548 }
13549
13550 // Should NOT have full precision
13551 passed = md.find("3.14159265") == std::string::npos;
13552 if (!passed) {
13553 std::cout << " [FAIL] : in pd_test_to_markdown_float_format() : full precision found (should be formatted)" << std::endl;
13554 throw std::runtime_error("pd_test_to_markdown_float_format failed");
13555 }
13556
13557 std::cout << " -> tests passed" << std::endl;
13558 }
13559
13560 // Test custom column alignment
13561 void pd_test_to_markdown_colalign() {
13562 std::cout << "========= custom column alignment ===================";
freq_to_seconds (pd_test_5_all.cpp:89804)
89794 df_in.add_column<double>("value", {1.0, 2.0, 3.0});
89795
89796 auto df = df_in.groupby("group").resample("D").sum();
89797 pandas_tests::check(df.nrows() == 3,
89798 "case_12_aggregate_string_daily.nrows==3", local_fail);
89799}
89800
89801void case_13_aggregate_string_ms_nonempty(int& local_fail) {
89802 std::cout << "-- case_13_aggregate_string_ms_nonempty\n";
89803 // Sub-second source spans 5 ms. aggregate_string_cols_ today computes
89804 // `period_sec = freq_to_seconds("ms") * 1 = 0` and the inner
89805 // `i >= period_start && i < period_start + 0` filter never matches.
89806 // Combined with the resampler's own ms short-circuit, the whole
89807 // result frame is empty (nrows == 0). Post-fix, ms buckets carry
89808 // the source's tag values.
89809 pandas::DataFrame df_in;
89810 df_in.set_index(std::make_shared<pandas::DatetimeIndex>(
89811 mk_idx({"2020-01-01T00:00:00.000",
89812 "2020-01-01T00:00:00.002",
89813 "2020-01-01T00:00:00.005"})));
89814 df_in.add_column<std::string>("group", {"g", "g", "g"});
has_cached_values (pd_test_1_all.cpp:19395)
19385 }
19386
19387 std::cout << " -> tests passed" << std::endl;
19388 }
19389
19390 void pd_test_series_cache() {
19391 std::cout << "========= cache management =========================================";
19392
19393 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
19394
19395 bool passed = s.has_cached_values() == false;
19396 if (!passed) {
19397 std::cout << " [FAIL] : in pd_test_series_cache() : initial cache not empty" << std::endl;
19398 throw std::runtime_error("pd_test_series_cache failed: initial cache not empty");
19399 }
19400
19401 // Trigger cache
19402 s.sum();
19403 s.mean();
19404 s.min();
19405 s.max();
infer_column_dtype (pd_test_5_all.cpp:81044)
81034 int max_level,
81035 int level,
81036 std::vector<std::pair<std::string, std::string>>& out) {
81037 pandas::io::flatten_dict(d, prefix, sep, max_level, level, out);
81038 }
81039 static const pandas::io::JsonValue* lookup_path(
81040 const pandas::io::JsonObject& root,
81041 const std::vector<std::string>& path) {
81042 return pandas::io::lookup_path(root, path);
81043 }
81044 static std::string infer_column_dtype(const std::vector<std::string>& vals,
81045 bool has_nan_token = true) {
81046 return pandas::io::infer_column_dtype(vals, has_nan_token);
81047 }
81048};
81049
81050using JsonValue = pandas::io::JsonValue;
81051using JsonObject = pandas::io::JsonObject;
81052using JsonArray = pandas::io::JsonArray;
81053
81054static void check_str(const std::string& label,
infer_dtype_override (pd_test_3_all.cpp:22817)
22807 throw std::runtime_error("test_timedelta64_to_ns: 2 h should be 7200000000000 ns, got " + std::to_string(ns_h));
22808
22809 std::cout << " -> test passed" << std::endl;
22810}
22811
22812void test_infer_int_override() {
22813 std::cout << " test_infer_int_override" << std::endl;
22814
22815 // Column [1.0, 2.0, 3.0] -- all whole numbers, should be int64
22816 std::vector<double> vals1{1.0, 2.0, 3.0};
22817 auto result1 = pandas::construct_helpers::infer_dtype_override(vals1, false);
22818 if (result1 != "int64")
22819 throw std::runtime_error("test_infer_int_override: [1.0,2.0,3.0] should infer as int64, got '" + result1 + "'");
22820
22821 // Column [1.5, 2.0] -- not all whole numbers
22822 std::vector<double> vals2{1.5, 2.0};
22823 auto result2 = pandas::construct_helpers::infer_dtype_override(vals2, false);
22824 if (result2 != "")
22825 throw std::runtime_error("test_infer_int_override: [1.5,2.0] should NOT infer as int, got '" + result2 + "'");
22826
22827 // Column [1.0, NaN] -- has NaN, should stay float64
infer_dtype_override_from_kinds (pd_test_5_all.cpp:94339)
94329 df.add_column<std::string>("s", { std::string("x"), std::string("y") });
94330 KVec col = { kv_str("a"), kv_str("b") };
94331 df.set_column_resolved("s", col);
94332 pandas_tests::check(df.column_dtype_override("s") == "string",
94333 "C_26h_case_159_set_column_string_replace()_dtype", local_fail);
94334}
94335
94336void case_200_inf_pure_int(int& local_fail) {
94337 std::cout << "-- case_200_inf_pure_int\n";
94338 KVec col = { kv_int(1) };
94339 std::string s = pandas::construct_helpers::infer_dtype_override_from_kinds(col);
94340 pandas_tests::check(s == "int64",
94341 "C_26h_case_200_inf_pure_int()_dtype", local_fail);
94342}
94343
94344void case_201_inf_int_with_na(int& local_fail) {
94345 std::cout << "-- case_201_inf_int_with_na\n";
94346 KVec col = { kv_int(1), kv_na() };
94347 std::string s = pandas::construct_helpers::infer_dtype_override_from_kinds(col);
94348 pandas_tests::check(s == "Int64",
94349 "C_26h_case_201_inf_int_with_na()_dtype", local_fail);
infer_float_repr_precision (pd_test_5_all.cpp:57296)
57286 f_test_astype_reindex_chain_coverage_23_main_ns::f_test_astype_reindex_chain_coverage_23_main();
57287}
57288
57289
57290// --- f_test_format_helpers_coverage_9.cpp ---
57291namespace f_test_format_helpers_coverage_9_main_ns {
57292
57293static void f_format_helpers_coverage_8b2f47_case_A01_empty_span_returns_min(int& local_fail) {
57294 std::cout << "-- case_A01_empty_span_returns_min\n";
57295 std::vector<double> v;
57296 int p = pandas::detail::infer_float_repr_precision(std::span<const double>(v));
57297 pandas_tests::check(p == 1,
57298 "format_helpers_coverage_8b2f47_case_A01.empty_returns_min1", local_fail);
57299}
57300
57301static void f_format_helpers_coverage_8b2f47_case_A02_all_integer_returns_min(int& local_fail) {
57302 std::cout << "-- case_A02_all_integer_returns_min\n";
57303 std::vector<double> v = {1.0, 2.0, 3.0};
57304 int p = pandas::detail::infer_float_repr_precision(std::span<const double>(v));
57305 pandas_tests::check(p == 1,
57306 "format_helpers_coverage_8b2f47_case_A02.all_integer_returns_min1", local_fail);
infer_freq (pd_test_3_all.cpp:9209)
9199 // Check 10 % 3 = 1
9200 if (std::abs(remainders[static_cast<size_t>(1)] - 1.0) > 0.001) {
9201 std::cout << " [FAIL] : in pd_test_3_all_series_rdivmod() : remainder[1] wrong" << std::endl;
9202 throw std::runtime_error("pd_test_3_all_series_rdivmod failed: remainder");
9203 }
9204
9205 std::cout << " -> tests passed" << std::endl;
9206}
9207
9208// ============================================================================
9209// Category 36: Plan 10 - infer_freq()
9210// ============================================================================
9211
9212void pd_test_3_all_infer_freq() {
9213 std::cout << "========= infer_freq() daily ======================";
9214
9215 // Create a DatetimeIndex with daily frequency
9216 constexpr int64_t NS_PER_DAY = 24LL * 60 * 60 * 1000000000LL;
9217 int64_t base_ns = 0; // 1970-01-01
9218
9219 std::vector<numpy::datetime64> dates;
info (pd_test_1_all.cpp:7122)
7112 }
7113 if (!empty_params_error) {
7114 std::cout << " [FAIL] : select_dtypes empty params should throw" << std::endl;
7115 throw std::runtime_error("pd_test_dataframe_select_dtypes failed: empty params error");
7116 }
7117
7118 std::cout << " -> tests passed" << std::endl;
7119 }
7120
7121 // =====================================================================
7122 // Test: info() method
7123 // =====================================================================
7124 void pd_test_dataframe_info() {
7125 std::cout << "========= info ========================";
7126
7127 // Test basic info() with stringstream
7128 std::map<std::string, std::vector<int>> data = {
7129 {"A", {1, 2, 3, 4, 5}},
7130 {"B", {10, 20, 30, 40, 50}},
7131 {"C", {100, 200, 300, 400, 500}}
7132 };
interval_range (pd_test_3_all.cpp:13614)
13604 }
13605
13606 std::cout << " -> tests passed" << std::endl;
13607}
13608
13609// ============================================================================
13610// Interval Range Tests
13611// ============================================================================
13612
13613void pd_test_top_level_interval_range() {
13614 std::cout << "========= interval_range() ============================";
13615
13616 // Test with start, end, periods
13617 pandas::IntervalArray<double> result = pandas::interval_range<double>(
13618 std::optional<double>(0.0),
13619 std::optional<double>(10.0),
13620 std::optional<int>(5),
13621 std::nullopt,
13622 "right"
13623 );
invalid_join_type (pd_test_5_all.cpp:73122)
73112 if (s.empty()) return true;
73113 char back = s.back();
73114 return !(back == ' ' || back == '\t' || back == '\n' || back == '\r');
73115}
73116
73117void case_1_invalid_join_type_format(int& local_fail) {
73118 std::cout << "-- case_1_invalid_join_type_format\n";
73119 check_eq_str(
73120 "case_1.invalid_join_type_left",
73121 "Invalid join type: left",
73122 pandas::error_messages::invalid_join_type("left"),
73123 local_fail);
73124 check_eq_str(
73125 "case_1.invalid_join_type_outer",
73126 "Invalid join type: outer",
73127 pandas::error_messages::invalid_join_type("outer"),
73128 local_fail);
73129 // Empty pass-through — guards against future refactors that would
73130 // crash on empty input.
73131 check_eq_str(
73132 "case_1.invalid_join_type_empty",
invalid_join_type_with_valid_set (pd_test_5_all.cpp:73143)
73133 "Invalid join type: ",
73134 pandas::error_messages::invalid_join_type(""),
73135 local_fail);
73136}
73137
73138void case_2_invalid_join_type_long_form(int& local_fail) {
73139 std::cout << "-- case_2_invalid_join_type_long_form\n";
73140 check_eq_str(
73141 "case_2.invalid_join_type_with_valid_set_foo",
73142 "Invalid join type: foo. Must be 'left', 'right', 'inner', or 'outer'.",
73143 pandas::error_messages::invalid_join_type_with_valid_set("foo"),
73144 local_fail);
73145 check_eq_str(
73146 "case_2.invalid_join_type_with_valid_set_left",
73147 "Invalid join type: left. Must be 'left', 'right', 'inner', or 'outer'.",
73148 pandas::error_messages::invalid_join_type_with_valid_set("left"),
73149 local_fail);
73150 // Asymmetry pin: the long-form variant must NOT equal the short form.
73151 pandas_tests::check(
73152 pandas::error_messages::invalid_join_type_with_valid_set("left") !=
73153 pandas::error_messages::invalid_join_type("left"),
iss (pd_test_2_all.cpp:10348)
10338 try {
10339 df.to_clipboard(true, '\t', false); // index=false
10340 } catch (const std::exception& e) {
10341 std::cout << " [FAIL] : in pd_test_to_clipboard_no_index() : exception: " << e.what() << std::endl;
10342 throw std::runtime_error("pd_test_to_clipboard_no_index failed");
10343 }
10344
10345#ifdef _WIN32
10346 std::string clipboard = get_clipboard_text_with_retry();
10347 // Without index, first line should be just "A"
10348 std::istringstream iss(clipboard);
10349 std::string first_line;
10350 std::getline(iss, first_line);
10351 passed = first_line == "A";
10352 if (!passed) {
10353 std::cout << " [FAIL] : in pd_test_to_clipboard_no_index() : first line was '" << first_line << "', expected 'A'" << std::endl;
10354 throw std::runtime_error("pd_test_to_clipboard_no_index failed");
10355 }
10356#endif
10357
10358 std::cout << " -> tests passed" << std::endl;
iss (pd_test_2_all.cpp:10348)
10338 try {
10339 df.to_clipboard(true, '\t', false); // index=false
10340 } catch (const std::exception& e) {
10341 std::cout << " [FAIL] : in pd_test_to_clipboard_no_index() : exception: " << e.what() << std::endl;
10342 throw std::runtime_error("pd_test_to_clipboard_no_index failed");
10343 }
10344
10345#ifdef _WIN32
10346 std::string clipboard = get_clipboard_text_with_retry();
10347 // Without index, first line should be just "A"
10348 std::istringstream iss(clipboard);
10349 std::string first_line;
10350 std::getline(iss, first_line);
10351 passed = first_line == "A";
10352 if (!passed) {
10353 std::cout << " [FAIL] : in pd_test_to_clipboard_no_index() : first line was '" << first_line << "', expected 'A'" << std::endl;
10354 throw std::runtime_error("pd_test_to_clipboard_no_index failed");
10355 }
10356#endif
10357
10358 std::cout << " -> tests passed" << std::endl;
iss (pd_test_2_all.cpp:10348)
10338 try {
10339 df.to_clipboard(true, '\t', false); // index=false
10340 } catch (const std::exception& e) {
10341 std::cout << " [FAIL] : in pd_test_to_clipboard_no_index() : exception: " << e.what() << std::endl;
10342 throw std::runtime_error("pd_test_to_clipboard_no_index failed");
10343 }
10344
10345#ifdef _WIN32
10346 std::string clipboard = get_clipboard_text_with_retry();
10347 // Without index, first line should be just "A"
10348 std::istringstream iss(clipboard);
10349 std::string first_line;
10350 std::getline(iss, first_line);
10351 passed = first_line == "A";
10352 if (!passed) {
10353 std::cout << " [FAIL] : in pd_test_to_clipboard_no_index() : first line was '" << first_line << "', expected 'A'" << std::endl;
10354 throw std::runtime_error("pd_test_to_clipboard_no_index failed");
10355 }
10356#endif
10357
10358 std::cout << " -> tests passed" << std::endl;
json_normalize (pd_test_3_all.cpp:9344)
9334 // Should have data columns: A, B (id and year are in the MultiIndex)
9335 if (result.ncols() != 2) {
9336 std::cout << " [FAIL] : in pd_test_3_all_wide_to_long() : expected 2 columns, got " << result.ncols() << std::endl;
9337 throw std::runtime_error("pd_test_3_all_wide_to_long failed: ncols");
9338 }
9339
9340 std::cout << " -> tests passed" << std::endl;
9341}
9342
9343void pd_test_3_all_json_normalize() {
9344 std::cout << "========= json_normalize() ========================";
9345
9346 // Test with single row to verify basic functionality
9347 // (json_normalize only extracts numeric columns to DataFrame)
9348 // Note: Multi-row test skipped due to padding logic issue in implementation
9349 std::vector<std::map<std::string, std::variant<double, std::string, std::vector<double>>>> data = {
9350 {{"id", 1.0}, {"score", 95.0}, {"age", 25.0}}
9351 };
9352
9353 pandas::DataFrame result = pandas::json_normalize(data);
json_normalize (pd_test_3_all.cpp:9344)
9334 // Should have data columns: A, B (id and year are in the MultiIndex)
9335 if (result.ncols() != 2) {
9336 std::cout << " [FAIL] : in pd_test_3_all_wide_to_long() : expected 2 columns, got " << result.ncols() << std::endl;
9337 throw std::runtime_error("pd_test_3_all_wide_to_long failed: ncols");
9338 }
9339
9340 std::cout << " -> tests passed" << std::endl;
9341}
9342
9343void pd_test_3_all_json_normalize() {
9344 std::cout << "========= json_normalize() ========================";
9345
9346 // Test with single row to verify basic functionality
9347 // (json_normalize only extracts numeric columns to DataFrame)
9348 // Note: Multi-row test skipped due to padding logic issue in implementation
9349 std::vector<std::map<std::string, std::variant<double, std::string, std::vector<double>>>> data = {
9350 {{"id", 1.0}, {"score", 95.0}, {"age", 25.0}}
9351 };
9352
9353 pandas::DataFrame result = pandas::json_normalize(data);
json_value_to_string (pd_test_5_all.cpp:81028)
81018 throw std::runtime_error("f_test_plan_08_table_read_table_9 failed");
81019 }
81020 std::cout << " -> tests passed" << std::endl;
81021}
81022
81023// --- f_test_plan_06_normalize_jsonvalue_9.cpp ---
81024
81025namespace f_test_plan_06_normalize_jsonvalue_9_ns {
81026
81027struct PIO {
81028 static std::string json_value_to_string(const pandas::io::JsonValue& v) {
81029 return pandas::io::json_value_to_string(v);
81030 }
81031 static void flatten_dict(const pandas::io::JsonObject& d,
81032 const std::string& prefix,
81033 const std::string& sep,
81034 int max_level,
81035 int level,
81036 std::vector<std::pair<std::string, std::string>>& out) {
81037 pandas::io::flatten_dict(d, prefix, sep, max_level, level, out);
81038 }
json_value_to_string (pd_test_5_all.cpp:81028)
81018 throw std::runtime_error("f_test_plan_08_table_read_table_9 failed");
81019 }
81020 std::cout << " -> tests passed" << std::endl;
81021}
81022
81023// --- f_test_plan_06_normalize_jsonvalue_9.cpp ---
81024
81025namespace f_test_plan_06_normalize_jsonvalue_9_ns {
81026
81027struct PIO {
81028 static std::string json_value_to_string(const pandas::io::JsonValue& v) {
81029 return pandas::io::json_value_to_string(v);
81030 }
81031 static void flatten_dict(const pandas::io::JsonObject& d,
81032 const std::string& prefix,
81033 const std::string& sep,
81034 int max_level,
81035 int level,
81036 std::vector<std::pair<std::string, std::string>>& out) {
81037 pandas::io::flatten_dict(d, prefix, sep, max_level, level, out);
81038 }
label_not_found (pd_test_5_all.cpp:72206)
72196 check_eq_str(
72197 "case_3.cat1_DuplicateLabel.kCannotReindexDuplicate",
72198 "cannot reindex on an axis with duplicate labels",
72199 std::string(pandas::error_messages::kCannotReindexDuplicate),
72200 local_fail);
72201
72202 // Category 2: IndexingError — "[<label>] not in index".
72203 check_eq_str(
72204 "case_3.cat2_Indexing.label_not_found_foo",
72205 "[foo] not in index",
72206 pandas::error_messages::label_not_found("foo"),
72207 local_fail);
72208
72209 // Category 3: MergeError — no common columns. Prefix match is the
72210 // plan_91a contract; the trailing kwargs are stable too.
72211 {
72212 std::string m = std::string(pandas::error_messages::kMergeNoCommonColumns);
72213 bool prefix_ok = m.rfind("No common columns to perform merge on", 0) == 0;
72214 pandas_tests::check(prefix_ok, "case_3.cat3_Merge.kMergeNoCommonColumns_prefix",
72215 local_fail);
72216 }
lreshape (pd_test_3_all.cpp:9281)
9271 }
9272
9273 std::cout << " -> tests passed" << std::endl;
9274}
9275
9276// ============================================================================
9277// Category 37: Plan 09 - Reshape Functions (lreshape, wide_to_long, json_normalize)
9278// ============================================================================
9279
9280void pd_test_3_all_lreshape() {
9281 std::cout << "========= lreshape() ==============================";
9282
9283 // Create wide-format data
9284 std::map<std::string, std::vector<double>> data = {
9285 {"id", {1.0, 2.0}},
9286 {"A1", {10.0, 20.0}},
9287 {"A2", {11.0, 21.0}},
9288 {"B1", {100.0, 200.0}},
9289 {"B2", {101.0, 201.0}}
9290 };
9291 pandas::DataFrame df(data);
make_offset_from_string (pd_test_3_all.cpp:24530)
24520int pd_test_boolean_mask_kleene_main() {
24521 return dataframe_tests_boolean_mask_kleene::pd_test_boolean_mask_kleene_main();
24522}
24523// ------------------- pd_test_boolean_mask_kleene.cpp (end) ---------------------------
24524
24525// ------------------- pd_test_shift_freq (start) ---------------------------
24526namespace dataframe_tests_shift_freq {
24527
24528void pd_test_shift_freq_make_offset() {
24529 std::cout << "========= make_offset_from_string ========================";
24530 auto d = pandas::shift_helpers::make_offset_from_string("D", 5);
24531 if (d->name() != "Day" || d->n() != 5)
24532 throw std::runtime_error("Day offset failed");
24533 auto b = pandas::shift_helpers::make_offset_from_string("B", 1);
24534 if (b->name() != "BusinessDay")
24535 throw std::runtime_error("BusinessDay offset failed");
24536 auto h = pandas::shift_helpers::make_offset_from_string("h", 2);
24537 if (h->name() != "Hour")
24538 throw std::runtime_error("Hour offset failed");
24539 auto m = pandas::shift_helpers::make_offset_from_string("min", 3);
24540 if (m->name() != "Minute")
make_series_from_data_arg (pd_test_5_all.cpp:76074)
76064 pandas::DataArg data; // kind defaults to DataArgKind::Unknown
76065 pandas::DTypeHint dt;
76066 pandas::IndexHint ih;
76067 pandas::NameHint nh;
76068
76069 bool caught_typed = false;
76070 bool caught_wrong_sibling = false;
76071 bool caught_fallback = false;
76072 std::string captured_what;
76073 try {
76074 (void)pandas::make_series_from_data_arg(data, dt, ih, nh);
76075 } catch (const pandas::IncompatibleDataArgError& e) {
76076 caught_typed = true;
76077 captured_what = e.what();
76078 } catch (const pandas::IncompatibleFuncArgError&) {
76079 caught_wrong_sibling = true;
76080 } catch (const std::exception&) {
76081 caught_fallback = true;
76082 }
76083 pandas_tests::check(caught_typed, "case_14.real_factory_throws_typed_data_sentinel", local_fail);
76084 pandas_tests::check(!caught_wrong_sibling, "case_14.real_factory_not_caught_as_func_sibling", local_fail);
maybe_promote (pd_test_5_all.cpp:54766)
54756 while ((pos = rep.find("False", pos)) != std::string::npos) {
54757 ++n_false; ++pos;
54758 }
54759 pandas_tests::check(n_false == 1,
54760 "25b.repr has exactly one 'False' (the original), not 3", local_fail);
54761}
54762
54763void case_25_c_maybe_promote_bool_int(int& local_fail) {
54764 std::cout << "---- 25c maybe_promote_bool_int\n";
54765
54766 std::string got = ::pandas::detail::maybe_promote(
54767 "bool", ::pandas::detail::FillKind::Int, /*has_missing=*/true);
54768 pandas_tests::check(got == "object",
54769 "25c.maybe_promote(bool,Int,true)=='object' (got '" + got + "')",
54770 local_fail);
54771
54772 // Sanity: with has_missing=false, dtype is preserved.
54773 std::string got2 = ::pandas::detail::maybe_promote(
54774 "bool", ::pandas::detail::FillKind::Int, /*has_missing=*/false);
54775 pandas_tests::check(got2 == "bool",
54776 "25c.maybe_promote(bool,Int,false)=='bool' (no missing -> no promo)",
memory_usage (pd_test_1_all.cpp:27063)
27053 }
27054
27055 std::cout << "====================================== [OK] pd_test_value_counts test suite ========================== " << std::endl;
27056 return 0;
27057 }
27058
27059} // namespace dataframe_tests
27060// ------------------- pd_test_value_counts.cpp (end) -----------------------------
27061
27062// ------------------- pd_test_memory_usage.cpp (start) -----------------------------
27063// Tests for DataFrame.memory_usage() - pandas-compatible memory usage reporting
27064
27065namespace dataframe_tests {
27066 namespace dataframe_tests_memory_usage {
27067
27068 void pd_test_memory_usage_basic() {
27069 std::cout << "========= basic memory_usage =======================";
27070
27071 // Create a simple DataFrame with multiple columns
27072 std::map<std::string, std::vector<double>> data;
27073 data["A"] = {1.0, 2.0, 3.0, 4.0, 5.0};
memory_usage_total (pd_test_1_all.cpp:27203)
27193 void pd_test_memory_usage_total() {
27194 std::cout << "========= memory_usage_total ========================";
27195
27196 std::map<std::string, std::vector<double>> data;
27197 data["A"] = {1.0, 2.0, 3.0};
27198 data["B"] = {4.0, 5.0, 6.0};
27199
27200 pandas::DataFrame df(data);
27201
27202 size_t total = df.memory_usage_total();
27203
27204 // Total should be positive
27205 bool passed = (total > 0);
27206 if (!passed) {
27207 std::cout << " [FAIL] : in pd_test_memory_usage_total() : Total memory should be positive" << std::endl;
27208 throw std::runtime_error("pd_test_memory_usage_total failed");
27209 }
27210
27211 std::cout << " -> tests passed" << std::endl;
27212 }
mi (pd_test_3_all.cpp:797)
787 numpy::NDArray<numpy::int64> codes1(std::vector<size_t>{4});
788 codes1.setElementAt({0}, 0); // x
789 codes1.setElementAt({1}, 1); // y
790 codes1.setElementAt({2}, 1); // y
791 codes1.setElementAt({3}, 0); // x
792
793 std::vector<numpy::NDArray<numpy::int64>> codes = {codes0, codes1};
794 std::vector<std::optional<std::string>> names = {"level_0", "level_1"};
795
796 pandas::MultiIndex mi(std::move(levels), std::move(codes), names);
797
798 // Remove unused levels
799 pandas::MultiIndex result = mi.remove_unused_levels();
800
801 // Result should have same size
802 if (result.size() != 4) {
803 std::cout << " [FAIL] : in pd_test_3_all_multiindex_remove_unused() : size should be 4" << std::endl;
804 throw std::runtime_error("pd_test_3_all_multiindex_remove_unused failed: size");
805 }
mi (pd_test_3_all.cpp:797)
787 numpy::NDArray<numpy::int64> codes1(std::vector<size_t>{4});
788 codes1.setElementAt({0}, 0); // x
789 codes1.setElementAt({1}, 1); // y
790 codes1.setElementAt({2}, 1); // y
791 codes1.setElementAt({3}, 0); // x
792
793 std::vector<numpy::NDArray<numpy::int64>> codes = {codes0, codes1};
794 std::vector<std::optional<std::string>> names = {"level_0", "level_1"};
795
796 pandas::MultiIndex mi(std::move(levels), std::move(codes), names);
797
798 // Remove unused levels
799 pandas::MultiIndex result = mi.remove_unused_levels();
800
801 // Result should have same size
802 if (result.size() != 4) {
803 std::cout << " [FAIL] : in pd_test_3_all_multiindex_remove_unused() : size should be 4" << std::endl;
804 throw std::runtime_error("pd_test_3_all_multiindex_remove_unused failed: size");
805 }
name (pd_test_1_all.cpp:295)
285 throw std::runtime_error("pd_test_boolean_array_reductions failed: mean");
286 }
287
288 std::cout << " -> tests passed" << std::endl;
289 }
290
291 void pd_test_boolean_array_dtype() {
292 std::cout << "========= BooleanArray: dtype ======================= ";
293
294 pandas::BooleanArray arr;
295 if (arr.dtype().name() != "boolean") {
296 std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype name should be 'boolean'" << std::endl;
297 throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype name");
298 }
299
300 if (arr.dtype().kind() != "b") {
301 std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype kind should be 'b'" << std::endl;
302 throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype kind");
303 }
304
305 std::cout << " -> tests passed" << std::endl;
name (pd_test_1_all.cpp:295)
285 throw std::runtime_error("pd_test_boolean_array_reductions failed: mean");
286 }
287
288 std::cout << " -> tests passed" << std::endl;
289 }
290
291 void pd_test_boolean_array_dtype() {
292 std::cout << "========= BooleanArray: dtype ======================= ";
293
294 pandas::BooleanArray arr;
295 if (arr.dtype().name() != "boolean") {
296 std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype name should be 'boolean'" << std::endl;
297 throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype name");
298 }
299
300 if (arr.dtype().kind() != "b") {
301 std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype kind should be 'b'" << std::endl;
302 throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype kind");
303 }
304
305 std::cout << " -> tests passed" << std::endl;
nanos_to_timestamp_str (pd_test_3_all.cpp:25141)
25131} // namespace dataframe_tests
25132
25133#include "../pandas/pd_datetime_utils.h"
25134#include "../pandas/pd_timestamp.h"
25135
25136namespace dataframe_tests {
25137namespace dataframe_tests_datetime_utils {
25138
25139void pd_test_datetime_utils_nanos_epoch() {
25140 std::cout << "========= nanos_to_timestamp_str: epoch ================";
25141 auto result = pandas::datetime_utils::nanos_to_timestamp_str(0);
25142 if (result != "1970-01-01 00:00:00")
25143 throw std::runtime_error("nanos_to_str epoch: got " + result);
25144 std::cout << " -> tests passed" << std::endl;
25145}
25146
25147void pd_test_datetime_utils_nanos_simple() {
25148 std::cout << "========= nanos_to_timestamp_str: 2023-06-15 12:30:45 ==";
25149 int64_t ns = pandas::Timestamp::componentsToNanos(2023, 6, 15, 12, 30, 45, 0, 0);
25150 auto result = pandas::datetime_utils::nanos_to_timestamp_str(ns);
25151 if (result != "2023-06-15 12:30:45")
normalize_date_string (pd_test_3_all.cpp:10607)
10597// Category 45: Period Range Parsing (Plan G3)
10598// ============================================================================
10599
10600namespace dataframe_tests_period_range_parsing {
10601
10602void pd_test_period_range_parsing_normalize() {
10603 std::cout << "========= normalize_date_string =======================";
10604 bool passed = true;
10605
10606 // US date: 1/1/2011 -> 2011-01-01
10607 std::string r1 = pandas::normalize_date_string("1/1/2011");
10608 if (r1 != "2011-01-01") {
10609 std::cout << " [FAIL] : 1/1/2011 -> " << r1 << " (expected 2011-01-01)" << std::endl;
10610 passed = false;
10611 }
10612
10613 // 2-digit year: 12/31/99 -> 2099-12-31
10614 std::string r2 = pandas::normalize_date_string("12/31/99");
10615 if (r2 != "2099-12-31") {
10616 std::cout << " [FAIL] : 12/31/99 -> " << r2 << " (expected 2099-12-31)" << std::endl;
10617 passed = false;
numeric_only_false (pd_test_5_all.cpp:74691)
74681 "kPeriodFreqMismatch must be const std::string_view");
74682 static_assert(std::is_same_v<decltype(pandas::error_messages::kStrAccessorRequiresString),
74683 const std::string_view>,
74684 "kStrAccessorRequiresString must be const std::string_view");
74685
74686 constexpr std::string_view k = pandas::error_messages::kAxisMustBe0Or1;
74687 static_assert(k.size() > 0, "kAxisMustBe0Or1 must have content");
74688
74689 // Format helpers exist and return std::string.
74690 static_assert(
74691 std::is_same_v<decltype(pandas::error_messages::numeric_only_false(std::string{})),
74692 std::string>,
74693 "numeric_only_false must return std::string");
74694 static_assert(
74695 std::is_same_v<decltype(pandas::error_messages::numeric_only_false_sum_hint(std::string{})),
74696 std::string>,
74697 "numeric_only_false_sum_hint must return std::string");
74698 static_assert(
74699 std::is_same_v<decltype(pandas::error_messages::cannot_compare_types(std::string{},
74700 std::string{})),
74701 std::string>,
numeric_only_false_sum_hint (pd_test_5_all.cpp:74695)
74685 constexpr std::string_view k = pandas::error_messages::kAxisMustBe0Or1;
74686 static_assert(k.size() > 0, "kAxisMustBe0Or1 must have content");
74687
74688 // Format helpers exist and return std::string.
74689 static_assert(
74690 std::is_same_v<decltype(pandas::error_messages::numeric_only_false(std::string{})),
74691 std::string>,
74692 "numeric_only_false must return std::string");
74693 static_assert(
74694 std::is_same_v<decltype(pandas::error_messages::numeric_only_false_sum_hint(std::string{})),
74695 std::string>,
74696 "numeric_only_false_sum_hint must return std::string");
74697 static_assert(
74698 std::is_same_v<decltype(pandas::error_messages::cannot_compare_types(std::string{},
74699 std::string{})),
74700 std::string>,
74701 "cannot_compare_types must return std::string");
74702 static_assert(
74703 std::is_same_v<decltype(pandas::error_messages::unsupported_binop(std::string{},
74704 std::string{},
ordinal_to_string (pd_test_3_all.cpp:22154)
22144void test_dt_to_period() {
22145 std::cout << "========= dt.to_period ===========================";
22146
22147 std::vector<numpy::datetime64> dates = {
22148 numpy::datetime64("2023-06-15")
22149 };
22150 pandas::Series<numpy::datetime64> s(dates);
22151
22152 auto result_d = s.dt().to_period("D");
22153 auto d_str = pandas::ordinal_to_string(result_d.at(0), result_d.freq());
22154 if (d_str != "2023-06-15") {
22155 throw std::runtime_error("dt.to_period(D): expected 2023-06-15, got " + d_str);
22156 }
22157
22158 auto result_m = s.dt().to_period("M");
22159 auto m_str = pandas::ordinal_to_string(result_m.at(0), result_m.freq());
22160 if (m_str != "2023-06") {
22161 throw std::runtime_error("dt.to_period(M): expected 2023-06, got " + m_str);
22162 }
out (pd_test_5_all.cpp:41536)
41526 for (size_t i = 0; i < v.size(); ++i) {
41527 if (i > 0) out += ", ";
41528 if (is_nan_d(v[i])) out += "NaT";
41529 else out += std::to_string(v[i]);
41530 }
41531 out += "]";
41532 return out;
41533}
41534
41535static std::vector<double> series_data(const pandas::Series<numpy::float64>& s) {
41536 std::vector<double> out(s.size());
41537 for (size_t i = 0; i < s.size(); ++i) {
41538 out[i] = static_cast<double>(s[i]);
41539 }
41540 return out;
41541}
41542
41543static void diag_pair(const pandas::Series<numpy::float64>& src,
41544 const pandas::Series<numpy::float64>& res,
41545 const char* tag) {
41546 std::cout << " " << tag << " source dtype="
out (pd_test_5_all.cpp:41536)
41526 for (size_t i = 0; i < v.size(); ++i) {
41527 if (i > 0) out += ", ";
41528 if (is_nan_d(v[i])) out += "NaT";
41529 else out += std::to_string(v[i]);
41530 }
41531 out += "]";
41532 return out;
41533}
41534
41535static std::vector<double> series_data(const pandas::Series<numpy::float64>& s) {
41536 std::vector<double> out(s.size());
41537 for (size_t i = 0; i < s.size(); ++i) {
41538 out[i] = static_cast<double>(s[i]);
41539 }
41540 return out;
41541}
41542
41543static void diag_pair(const pandas::Series<numpy::float64>& src,
41544 const pandas::Series<numpy::float64>& res,
41545 const char* tag) {
41546 std::cout << " " << tag << " source dtype="
pairwise_common_type (pd_test_5_all.cpp:40076)
40066 std::cout << "-- case_41_axis1_bool_int_B_int64\n";
40067 auto out = concat_axis1(df1<bool>("A", true), df1<std::int64_t>("B", 1));
40068 auto got = col_dtype(out, "B");
40069 pandas_tests::check(got == "int64",
40070 "case_41.axis1.B == int64 (got '" + got + "')",
40071 local_fail);
40072}
40073
40074void f_concat_df_bool_int_524871_case_42_series_helper_bool_int8_object(int& local_fail) {
40075 std::cout << "-- case_42_series_helper_bool_int8_object\n";
40076 auto got = pandas::detail::pairwise_common_type("bool", "int8");
40077 pandas_tests::check(got == "object",
40078 "case_42.pairwise(bool,int8) == object (got '" + got + "')",
40079 local_fail);
40080}
40081
40082void f_concat_df_bool_int_524871_case_43_series_helper_bool_int16_object(int& local_fail) {
40083 std::cout << "-- case_43_series_helper_bool_int16_object\n";
40084 auto got = pandas::detail::pairwise_common_type("bool", "int16");
40085 pandas_tests::check(got == "object",
40086 "case_43.pairwise(bool,int16) == object (got '" + got + "')",
parse_base_freq (pd_test_5_all.cpp:101481)
101471 const pandas::Hour* h = dynamic_cast<const pandas::Hour*>(off.get());
101472 pandas_tests::check(h != nullptr,
101473 "f_core_02_freq_factory_c02f7a_case_70.5H_is_Hour", local_fail);
101474 if (h) {
101475 pandas_tests::check(h->n() == 5,
101476 "f_core_02_freq_factory_c02f7a_case_70.5H_n5", local_fail);
101477 }
101478 // The legacy resampler classifier strips the multiplier itself; pass the
101479 // bare unit to mirror its call site.
101480 pandas_tests::check(
101481 pandas::parse_base_freq("H") == pandas::ResampleFreq::HOURLY,
101482 "f_core_02_freq_factory_c02f7a_case_70.H_resample_enum", local_fail);
101483}
101484
101485void f_core_02_freq_factory_c02f7a_case_71_sweep_resampler_Y(int& local_fail) {
101486 std::cout << "-- case_71_sweep_resampler_Y\n";
101487 // Yearly. Factory's ParsedFreq.base must be in the YEARLY-equivalent
101488 // set the legacy resampler if-chain matches against.
101489 pandas::DateOffset::ParsedFreq p =
101490 pandas::DateOffset::parse_freq_string("Y");
101491 bool yearly_base =
parse_closed_param (pd_test_3_all.cpp:24646)
24636}
24637// ------------------- pd_test_shift_freq (end) ---------------------------
24638
24639// ------------------- pd_test_rolling_time (begin) ---------------------------
24640#include "../pandas/pd_rolling.h"
24641
24642namespace dataframe_tests_rolling_time {
24643
24644void pd_test_rolling_time_parse_closed() {
24645 std::cout << "========= parse_closed_param =======================";
24646 if (pandas::parse_closed_param("") != 0)
24647 throw std::runtime_error("empty string should map to 0");
24648 if (pandas::parse_closed_param("right") != 0)
24649 throw std::runtime_error("'right' should map to 0");
24650 if (pandas::parse_closed_param("left") != 1)
24651 throw std::runtime_error("'left' should map to 1");
24652 if (pandas::parse_closed_param("both") != 2)
24653 throw std::runtime_error("'both' should map to 2");
24654 if (pandas::parse_closed_param("neither") != 3)
24655 throw std::runtime_error("'neither' should map to 3");
24656 std::cout << " -> tests passed" << std::endl;
parse_interval_closed (pd_test_5_all.cpp:69015)
69005 []() {
69006 (void)pandas::parse_period_freq("not_a_freq");
69007 },
69008 local_fail);
69009}
69010
69011void f_pybind_type_error_translator_9_5832641_case_18_interval_closed_invalid(int& local_fail) {
69012 std::cout << "-- f_pybind_type_error_translator_9_5832641_case_18_interval_closed_invalid\n";
69013 expect_invalid_argument("case_18_interval_closed_invalid",
69014 []() {
69015 (void)pandas::parse_interval_closed("invalid");
69016 },
69017 local_fail);
69018}
69019
69020void f_pybind_type_error_translator_9_5832641_case_19_timedelta_unknown_unit(int& local_fail) {
69021 std::cout << "-- f_pybind_type_error_translator_9_5832641_case_19_timedelta_unknown_unit\n";
69022 expect_invalid_argument("case_19_timedelta_unknown_unit",
69023 []() {
69024 (void)pandas::Timedelta("5zz");
69025 },
parse_offset_to_seconds (pd_test_5_all.cpp:101504)
101494 pandas_tests::check(yearly_base,
101495 "f_core_02_freq_factory_c02f7a_case_71.Y_yearly_base", local_fail);
101496 pandas_tests::check(
101497 pandas::parse_base_freq("Y") == pandas::ResampleFreq::YEARLY,
101498 "f_core_02_freq_factory_c02f7a_case_71.Y_resample_enum", local_fail);
101499}
101500
101501void f_core_02_freq_factory_c02f7a_case_72_sweep_offset_utils_D(int& local_fail) {
101502 std::cout << "-- case_72_sweep_offset_utils_D\n";
101503 // Target 6 of the Change Core-2.5 sweep: pd_offset_utils.h:38-55
101504 // parse_offset_to_seconds(). Factory must accept "D" and produce a
101505 // Day subclass; legacy classifier must return 86400 (24*60*60).
101506 std::unique_ptr<pandas::DateOffset> off =
101507 pandas::DateOffset::from_freq_string("D");
101508 pandas_tests::check(off != nullptr,
101509 "f_core_02_freq_factory_c02f7a_case_72.D_not_null", local_fail);
101510 pandas_tests::check(dynamic_cast<const pandas::Day*>(off.get()) != nullptr,
101511 "f_core_02_freq_factory_c02f7a_case_72.D_is_Day", local_fail);
101512 // Legacy parse_offset_to_seconds in pd_offset_utils.h must still agree.
101513 pandas_tests::check(
101514 pandas::parse_offset_to_seconds("D") == 86400LL,
parse_period_freq (pd_test_5_all.cpp:69006)
68996 // Same name twice — must throw on the uniqueness check.
68997 (void)ca.rename_categories(std::vector<std::string>{"dup", "dup"});
68998 },
68999 local_fail);
69000}
69001
69002void f_pybind_type_error_translator_9_5832641_case_17_period_freq_invalid(int& local_fail) {
69003 std::cout << "-- f_pybind_type_error_translator_9_5832641_case_17_period_freq_invalid\n";
69004 expect_invalid_argument("case_17_period_freq_invalid",
69005 []() {
69006 (void)pandas::parse_period_freq("not_a_freq");
69007 },
69008 local_fail);
69009}
69010
69011void f_pybind_type_error_translator_9_5832641_case_18_interval_closed_invalid(int& local_fail) {
69012 std::cout << "-- f_pybind_type_error_translator_9_5832641_case_18_interval_closed_invalid\n";
69013 expect_invalid_argument("case_18_interval_closed_invalid",
69014 []() {
69015 (void)pandas::parse_interval_closed("invalid");
69016 },
partial_string_getitem (pd_test_3_all.cpp:25296)
25286 std::cout << " [FAIL] : expected 0 entries, got " << result.size() << std::endl;
25287 throw std::runtime_error("slice_by_ns_range empty failed");
25288 }
25289 std::cout << " -> tests passed" << std::endl;
25290}
25291
25292void pd_test_datetime_range_partial_year() {
25293 std::cout << "========= partial_string_getitem year ====================";
25294 auto s = make_hourly_series(48);
25295 const auto* dti = dynamic_cast<const pandas::DatetimeIndex*>(&s.index());
25296 auto r = pandas::datetime_utils::partial_string_getitem(s, *dti, "2013");
25297 if (r.kind != pandas::datetime_utils::PartialDateResult::Kind::RANGE) {
25298 std::cout << " [FAIL] : expected RANGE" << std::endl;
25299 throw std::runtime_error("partial year kind failed");
25300 }
25301 if (r.range_series.size() != 48) {
25302 std::cout << " [FAIL] : expected 48 entries, got " << r.range_series.size() << std::endl;
25303 throw std::runtime_error("partial year count failed");
25304 }
25305 std::cout << " -> tests passed" << std::endl;
25306}
period_idx (pd_test_2_all.cpp:16556)
16546#include "../pandas/pd_dataframe.h"
16547
16548namespace dataframe_tests {
16549 namespace dataframe_tests_to_timestamp {
16550
16551 void pd_test_to_timestamp_basic() {
16552 std::cout << "========= basic to_timestamp functionality =============";
16553
16554 // Create a PeriodIndex with yearly periods
16555 std::vector<std::string> periods = {"2023", "2024", "2025"};
16556 pandas::PeriodIndex period_idx(periods, "Y", "year_idx");
16557
16558 // Create DataFrame with PeriodIndex
16559 std::map<std::string, std::vector<double>> data;
16560 data["col1"] = {1.0, 2.0, 3.0};
16561 data["col2"] = {4.0, 5.0, 6.0};
16562 pandas::DataFrame df(data);
16563 df.set_index(std::make_unique<pandas::PeriodIndex>(period_idx));
16564
16565 // Verify it's a PeriodIndex
16566 const pandas::PeriodIndex* pidx = dynamic_cast<const pandas::PeriodIndex*>(&df.index());
period_idx (pd_test_2_all.cpp:16556)
16546#include "../pandas/pd_dataframe.h"
16547
16548namespace dataframe_tests {
16549 namespace dataframe_tests_to_timestamp {
16550
16551 void pd_test_to_timestamp_basic() {
16552 std::cout << "========= basic to_timestamp functionality =============";
16553
16554 // Create a PeriodIndex with yearly periods
16555 std::vector<std::string> periods = {"2023", "2024", "2025"};
16556 pandas::PeriodIndex period_idx(periods, "Y", "year_idx");
16557
16558 // Create DataFrame with PeriodIndex
16559 std::map<std::string, std::vector<double>> data;
16560 data["col1"] = {1.0, 2.0, 3.0};
16561 data["col2"] = {4.0, 5.0, 6.0};
16562 pandas::DataFrame df(data);
16563 df.set_index(std::make_unique<pandas::PeriodIndex>(period_idx));
16564
16565 // Verify it's a PeriodIndex
16566 const pandas::PeriodIndex* pidx = dynamic_cast<const pandas::PeriodIndex*>(&df.index());
pluralize_offset_name (pd_test_5_all.cpp:124417)
124407 } catch (const std::exception& e) {
124408 std::cout << " oracle load failed: " << e.what() << "\n";
124409 ok = false;
124410 }
124411 pandas_tests::check(ok, "f_dateoffset_repr_226538_case_34.oracle_csv", local_fail);
124412}
124413
124414void f_dateoffset_repr_226538_case_35_virtual_dispatch(int& local_fail) {
124415 std::cout << "-- case_35_virtual_dispatch\n";
124416 // Plain default-inherited path: Day(2) reached via DateOffset* must use
124417 // pluralize_offset_name(name(), n_) and produce "<2 * Days>".
124418 std::unique_ptr<pandas::DateOffset> p = std::make_unique<pandas::Day>(2);
124419 std::string via_base = p->repr();
124420 std::string via_static = pandas::Day(2).repr();
124421 // Anchored override path: YearEnd(1, month=6) reached via DateOffset*
124422 // must dispatch to YearEnd::repr() and produce "<YearEnd: month=6>".
124423 std::unique_ptr<pandas::DateOffset> q = std::make_unique<pandas::YearEnd>(1, false, 6);
124424 std::string anchored = q->repr();
124425 bool ok = (via_base == "<2 * Days>")
124426 && (via_static == "<2 * Days>")
124427 && (anchored == "<YearEnd: month=6>");
promote_for_fill (pd_test_5_all.cpp:97421)
97411};
97412
97413static void expect_promote(const std::string& tag,
97414 std::string_view src,
97415 pandas::FillValue fv,
97416 bool has_missing,
97417 const std::string& expected,
97418 int& local_fail) {
97419 std::string out;
97420 try {
97421 out = pandas::detail::promote_for_fill(src, fv, has_missing);
97422 } catch (const std::exception& e) {
97423 std::cout << " exception: " << e.what() << "\n";
97424 out = "<exc>";
97425 }
97426 bool ok = (out == expected);
97427 pandas_tests::check(ok, "promote_for_fill_" + tag + "()", local_fail);
97428 if (!ok) {
97429 std::cout << " src=[" << src << "] expected=[" << expected
97430 << "] got=[" << out << "]\n";
97431 }
propagate_aligned_dtype (pd_test_5_all.cpp:93017)
93007 std::cout << "-- case_27_propagate_dtype_nan_suppresses()\n";
93008 int local_fail = 0;
93009 auto df = make_1row_df();
93010 std::string col_before = df.dtype_string("x");
93011
93012 pandas::AlignmentResult ar;
93013 ar.kind = pandas::SetItemResult::PARTIAL_ALIGN;
93014 ar.has_nan_from_upcasting = true;
93015 ar.aligned_values = {std::numeric_limits<double>::quiet_NaN()};
93016
93017 pandas::propagate_aligned_dtype<std::int64_t>(df, std::string("x"), ar,
93018 std::string("int64"));
93019 std::string col_after = df.dtype_string("x");
93020 pandas_tests::check(col_before == col_after,
93021 "f_test_25_propagate_dtype_nan_suppresses_604113.dtype_unchanged",
93022 local_fail);
93023}
93024
93025void case_28_propagate_dtype_no_nan_writes() {
93026 // has_nan_from_upcasting=false => propagation occurs; column dtype set.
93027 std::cout << "-- case_28_propagate_dtype_no_nan_writes()\n";
qcut (pd_test_3_all.cpp:13518)
13508 pandas::CutResult<double> result3 = pandas::cut<double>(x, edges, true, custom_labels);
13509 if (result3.labels[0] != "low" || result3.labels[1] != "medium" || result3.labels[2] != "high") {
13510 std::cout << " [FAIL] : in pd_test_top_level_cut() : custom labels not applied" << std::endl;
13511 throw std::runtime_error("pd_test_top_level_cut failed: custom labels");
13512 }
13513
13514 std::cout << " -> tests passed" << std::endl;
13515}
13516
13517void pd_test_top_level_qcut() {
13518 std::cout << "========= qcut() ======================================";
13519
13520 std::vector<double> x = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
13521
13522 // Test qcut with 4 quantiles (quartiles)
13523 pandas::CutResult<double> result = pandas::qcut<double>(x, 4);
13524 // Should have approximately 4 bins (may be fewer if duplicates)
13525 if (result.bins.size() < 2) {
13526 std::cout << " [FAIL] : in pd_test_top_level_qcut() : qcut should create bins" << std::endl;
13527 throw std::runtime_error("pd_test_top_level_qcut failed: no bins created");
13528 }
qcut (pd_test_3_all.cpp:13518)
13508 pandas::CutResult<double> result3 = pandas::cut<double>(x, edges, true, custom_labels);
13509 if (result3.labels[0] != "low" || result3.labels[1] != "medium" || result3.labels[2] != "high") {
13510 std::cout << " [FAIL] : in pd_test_top_level_cut() : custom labels not applied" << std::endl;
13511 throw std::runtime_error("pd_test_top_level_cut failed: custom labels");
13512 }
13513
13514 std::cout << " -> tests passed" << std::endl;
13515}
13516
13517void pd_test_top_level_qcut() {
13518 std::cout << "========= qcut() ======================================";
13519
13520 std::vector<double> x = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
13521
13522 // Test qcut with 4 quantiles (quartiles)
13523 pandas::CutResult<double> result = pandas::qcut<double>(x, 4);
13524 // Should have approximately 4 bins (may be fewer if duplicates)
13525 if (result.bins.size() < 2) {
13526 std::cout << " [FAIL] : in pd_test_top_level_qcut() : qcut should create bins" << std::endl;
13527 throw std::runtime_error("pd_test_top_level_qcut failed: no bins created");
13528 }
r (pd_test_3_all.cpp:11063)
11053}
11054
11055void pd_test_3_all_groupby_column_transform() {
11056 std::cout << "========= GroupBy.column<T>().transform() ===============";
11057 pandas::DataFrame df;
11058 df.add_column<std::string>("Sector", {"Tech","Tech","Fin","Fin"});
11059 df.add_column<double>("Return", {10.0, 20.0, 30.0, 40.0});
11060 auto demeaned = df.groupby("Sector").column<double>("Return").transform(
11061 [](const std::vector<double>& x) {
11062 double m = 0; for (double v : x) m += v; m /= x.size();
11063 std::vector<double> r(x.size());
11064 for (size_t i = 0; i < x.size(); ++i) r[i] = x[i] - m;
11065 return r;
11066 });
11067 if (demeaned.size() != 4 || std::abs(demeaned[0] - (-5.0)) > 1e-9) {
11068 std::cout << " [FAIL] : in pd_test_3_all_groupby_column_transform()" << std::endl;
11069 throw std::runtime_error("groupby column transform failed");
11070 }
11071 std::cout << " -> tests passed" << std::endl;
11072}
read_clipboard (pd_test_3_all.cpp:13846)
13836 try {
13837 func();
13838 std::cout << " [FAIL] : " << name << " should throw" << std::endl;
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
read_csv (pd_test_1_all.cpp:13388)
13378 }
13379
13380 void pd_test_io_read_csv() {
13381 std::cout << "========= read_csv ===============================";
13382
13383 std::string csv_data = "name,value,count\n"
13384 "alpha,10.5,100\n"
13385 "beta,20.3,200\n"
13386 "gamma,30.1,300\n";
13387
13388 pandas::DataFrame df = pandas::DataFrame::read_csv(csv_data);
13389
13390 bool passed = (df.nrows() == 3 && df.ncols() == 3);
13391
13392 const auto& cols = df.columns();
13393 bool has_name = false, has_value = false, has_count = false;
13394 for (size_t i = 0; i < cols.size(); ++i) {
13395 std::string c = cols[i];
13396 if (c == "name") has_name = true;
13397 if (c == "value") has_value = true;
13398 if (c == "count") has_count = true;
read_csv (pd_test_1_all.cpp:13388)
13378 }
13379
13380 void pd_test_io_read_csv() {
13381 std::cout << "========= read_csv ===============================";
13382
13383 std::string csv_data = "name,value,count\n"
13384 "alpha,10.5,100\n"
13385 "beta,20.3,200\n"
13386 "gamma,30.1,300\n";
13387
13388 pandas::DataFrame df = pandas::DataFrame::read_csv(csv_data);
13389
13390 bool passed = (df.nrows() == 3 && df.ncols() == 3);
13391
13392 const auto& cols = df.columns();
13393 bool has_name = false, has_value = false, has_count = false;
13394 for (size_t i = 0; i < cols.size(); ++i) {
13395 std::string c = cols[i];
13396 if (c == "name") has_name = true;
13397 if (c == "value") has_value = true;
13398 if (c == "count") has_count = true;
read_csv (pd_test_1_all.cpp:13388)
13378 }
13379
13380 void pd_test_io_read_csv() {
13381 std::cout << "========= read_csv ===============================";
13382
13383 std::string csv_data = "name,value,count\n"
13384 "alpha,10.5,100\n"
13385 "beta,20.3,200\n"
13386 "gamma,30.1,300\n";
13387
13388 pandas::DataFrame df = pandas::DataFrame::read_csv(csv_data);
13389
13390 bool passed = (df.nrows() == 3 && df.ncols() == 3);
13391
13392 const auto& cols = df.columns();
13393 bool has_name = false, has_value = false, has_count = false;
13394 for (size_t i = 0; i < cols.size(); ++i) {
13395 std::string c = cols[i];
13396 if (c == "name") has_name = true;
13397 if (c == "value") has_value = true;
13398 if (c == "count") has_count = true;
read_csv (pd_test_1_all.cpp:13388)
13378 }
13379
13380 void pd_test_io_read_csv() {
13381 std::cout << "========= read_csv ===============================";
13382
13383 std::string csv_data = "name,value,count\n"
13384 "alpha,10.5,100\n"
13385 "beta,20.3,200\n"
13386 "gamma,30.1,300\n";
13387
13388 pandas::DataFrame df = pandas::DataFrame::read_csv(csv_data);
13389
13390 bool passed = (df.nrows() == 3 && df.ncols() == 3);
13391
13392 const auto& cols = df.columns();
13393 bool has_name = false, has_value = false, has_count = false;
13394 for (size_t i = 0; i < cols.size(); ++i) {
13395 std::string c = cols[i];
13396 if (c == "name") has_name = true;
13397 if (c == "value") has_value = true;
13398 if (c == "count") has_count = true;
read_excel (pd_test_3_all.cpp:13847)
13837 func();
13838 std::cout << " [FAIL] : " << name << " should throw" << std::endl;
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
read_excel (pd_test_3_all.cpp:13847)
13837 func();
13838 std::cout << " [FAIL] : " << name << " should throw" << std::endl;
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
read_excel (pd_test_3_all.cpp:13847)
13837 func();
13838 std::cout << " [FAIL] : " << name << " should throw" << std::endl;
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
read_excel (pd_test_3_all.cpp:13847)
13837 func();
13838 std::cout << " [FAIL] : " << name << " should throw" << std::endl;
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
read_feather (pd_test_3_all.cpp:13848)
13838 std::cout << " [FAIL] : " << name << " should throw" << std::endl;
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
read_feather (pd_test_3_all.cpp:13848)
13838 std::cout << " [FAIL] : " << name << " should throw" << std::endl;
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
read_hdf (pd_test_2_all.cpp:11643)
11633 std::map<std::string, std::vector<double>> data = {
11634 {"col1", {1.0, 2.0}},
11635 {"col2", {4.0, 3.0}}
11636 };
11637 pandas::DataFrame df(data);
11638
11639 std::string temp_path = "temp/test_hdf5_basic.h5";
11640 df.to_hdf(temp_path, "my_key", "w");
11641
11642 // Read back and verify
11643 pandas::DataFrame df2 = pandas::DataFrame::read_hdf(temp_path, "my_key");
11644
11645 if (df2.nrows() != 2 || df2.ncols() != 2) {
11646 std::cout << " [FAIL] : wrong dimensions" << std::endl;
11647 std::remove(temp_path.c_str());
11648 throw std::runtime_error("pd_test_to_hdf_basic failed");
11649 }
11650
11651 std::remove(temp_path.c_str());
11652 std::cout << " -> tests passed" << std::endl;
11653 }
read_hdf (pd_test_2_all.cpp:11643)
11633 std::map<std::string, std::vector<double>> data = {
11634 {"col1", {1.0, 2.0}},
11635 {"col2", {4.0, 3.0}}
11636 };
11637 pandas::DataFrame df(data);
11638
11639 std::string temp_path = "temp/test_hdf5_basic.h5";
11640 df.to_hdf(temp_path, "my_key", "w");
11641
11642 // Read back and verify
11643 pandas::DataFrame df2 = pandas::DataFrame::read_hdf(temp_path, "my_key");
11644
11645 if (df2.nrows() != 2 || df2.ncols() != 2) {
11646 std::cout << " [FAIL] : wrong dimensions" << std::endl;
11647 std::remove(temp_path.c_str());
11648 throw std::runtime_error("pd_test_to_hdf_basic failed");
11649 }
11650
11651 std::remove(temp_path.c_str());
11652 std::cout << " -> tests passed" << std::endl;
11653 }
read_json (pd_test_1_all.cpp:13416)
13406 std::cout << " -> tests passed" << std::endl;
13407 }
13408
13409 void pd_test_io_read_json() {
13410 std::cout << "========= read_json ==============================";
13411
13412 // Columns orientation JSON
13413 std::string json_data = "{\"A\":[1,2,3],\"B\":[4,5,6]}";
13414
13415 pandas::DataFrame df = pandas::DataFrame::read_json(json_data, "columns");
13416
13417 bool passed = (df.nrows() == 3 && df.ncols() == 2);
13418
13419 if (!passed) {
13420 std::cout << " [FAIL] : in pd_test_io_read_json() : read_json failed, rows="
13421 << df.nrows() << " cols=" << df.ncols() << std::endl;
13422 throw std::runtime_error("pd_test_io_read_json failed");
13423 }
13424
13425 std::cout << " -> tests passed" << std::endl;
read_json (pd_test_1_all.cpp:13416)
13406 std::cout << " -> tests passed" << std::endl;
13407 }
13408
13409 void pd_test_io_read_json() {
13410 std::cout << "========= read_json ==============================";
13411
13412 // Columns orientation JSON
13413 std::string json_data = "{\"A\":[1,2,3],\"B\":[4,5,6]}";
13414
13415 pandas::DataFrame df = pandas::DataFrame::read_json(json_data, "columns");
13416
13417 bool passed = (df.nrows() == 3 && df.ncols() == 2);
13418
13419 if (!passed) {
13420 std::cout << " [FAIL] : in pd_test_io_read_json() : read_json failed, rows="
13421 << df.nrows() << " cols=" << df.ncols() << std::endl;
13422 throw std::runtime_error("pd_test_io_read_json failed");
13423 }
13424
13425 std::cout << " -> tests passed" << std::endl;
read_json (pd_test_1_all.cpp:13416)
13406 std::cout << " -> tests passed" << std::endl;
13407 }
13408
13409 void pd_test_io_read_json() {
13410 std::cout << "========= read_json ==============================";
13411
13412 // Columns orientation JSON
13413 std::string json_data = "{\"A\":[1,2,3],\"B\":[4,5,6]}";
13414
13415 pandas::DataFrame df = pandas::DataFrame::read_json(json_data, "columns");
13416
13417 bool passed = (df.nrows() == 3 && df.ncols() == 2);
13418
13419 if (!passed) {
13420 std::cout << " [FAIL] : in pd_test_io_read_json() : read_json failed, rows="
13421 << df.nrows() << " cols=" << df.ncols() << std::endl;
13422 throw std::runtime_error("pd_test_io_read_json failed");
13423 }
13424
13425 std::cout << " -> tests passed" << std::endl;
read_json (pd_test_1_all.cpp:13416)
13406 std::cout << " -> tests passed" << std::endl;
13407 }
13408
13409 void pd_test_io_read_json() {
13410 std::cout << "========= read_json ==============================";
13411
13412 // Columns orientation JSON
13413 std::string json_data = "{\"A\":[1,2,3],\"B\":[4,5,6]}";
13414
13415 pandas::DataFrame df = pandas::DataFrame::read_json(json_data, "columns");
13416
13417 bool passed = (df.nrows() == 3 && df.ncols() == 2);
13418
13419 if (!passed) {
13420 std::cout << " [FAIL] : in pd_test_io_read_json() : read_json failed, rows="
13421 << df.nrows() << " cols=" << df.ncols() << std::endl;
13422 throw std::runtime_error("pd_test_io_read_json failed");
13423 }
13424
13425 std::cout << " -> tests passed" << std::endl;
read_parquet (pd_test_3_all.cpp:13849)
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
read_parquet (pd_test_3_all.cpp:13849)
13839 return false;
13840 } catch (const std::exception&) {
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
read_pickle (pd_test_3_all.cpp:13851)
13841 return true;
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13860 }
read_sas (pd_test_3_all.cpp:13852)
13842 }
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13860 }
13861
13862 std::cout << " -> tests passed" << std::endl;
read_spss (pd_test_3_all.cpp:13853)
13843 };
13844
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13860 }
13861
13862 std::cout << " -> tests passed" << std::endl;
13863}
read_sql (pd_test_3_all.cpp:13855)
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13860 }
13861
13862 std::cout << " -> tests passed" << std::endl;
13863}
13864
13865// ============================================================================
read_sql (pd_test_3_all.cpp:13855)
13845 bool all_passed = true;
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13860 }
13861
13862 std::cout << " -> tests passed" << std::endl;
13863}
13864
13865// ============================================================================
read_stata (pd_test_3_all.cpp:13854)
13844 bool all_passed = true;
13845 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13846 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13847 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13848 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13849 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13850 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13851 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13852 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13853 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13854 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13855 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13856
13857 if (!all_passed) {
13858 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13859 }
13860
13861 std::cout << " -> tests passed" << std::endl;
13862}
read_stata (pd_test_3_all.cpp:13854)
13844 bool all_passed = true;
13845 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13846 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13847 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13848 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13849 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13850 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13851 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13852 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13853 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13854 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13855 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13856
13857 if (!all_passed) {
13858 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13859 }
13860
13861 std::cout << " -> tests passed" << std::endl;
13862}
read_table (pd_test_5_all.cpp:80121)
80111 std::cout << " -> tests passed" << std::endl;
80112}
80113
80114// --- f_test_plan_08_table_read_table_9.cpp ---
80115
80116namespace f_test_plan_08_table_read_table_9_ns {
80117
80118struct Detect {
80119 template <class S>
80120 static auto detect_options_map_2arg(int) -> decltype(
80121 pandas::read_table(
80122 std::declval<const S&>(),
80123 std::declval<const std::map<std::string,
80124 pandas::DataFrame::CsvOption>&>()),
80125 std::true_type{});
80126
80127 template <class S>
80128 static auto detect_options_map_2arg(...) -> std::false_type;
80129
80130 static constexpr bool has_options_map_overload =
80131 decltype(detect_options_map_2arg<std::string>(0))::value;
read_table (pd_test_5_all.cpp:80121)
80111 std::cout << " -> tests passed" << std::endl;
80112}
80113
80114// --- f_test_plan_08_table_read_table_9.cpp ---
80115
80116namespace f_test_plan_08_table_read_table_9_ns {
80117
80118struct Detect {
80119 template <class S>
80120 static auto detect_options_map_2arg(int) -> decltype(
80121 pandas::read_table(
80122 std::declval<const S&>(),
80123 std::declval<const std::map<std::string,
80124 pandas::DataFrame::CsvOption>&>()),
80125 std::true_type{});
80126
80127 template <class S>
80128 static auto detect_options_map_2arg(...) -> std::false_type;
80129
80130 static constexpr bool has_options_map_overload =
80131 decltype(detect_options_map_2arg<std::string>(0))::value;
read_xml (pd_test_3_all.cpp:13856)
13846 all_passed &= test_throws("read_clipboard", []() { pandas::read_clipboard(); });
13847 all_passed &= test_throws("read_excel", []() { pandas::read_excel("test.xlsx"); });
13848 all_passed &= test_throws("read_feather", []() { pandas::read_feather("test.feather"); });
13849 all_passed &= test_throws("read_parquet", []() { pandas::read_parquet("test.parquet"); });
13850 all_passed &= test_throws("read_hdf", []() { pandas::read_hdf("test.h5"); });
13851 all_passed &= test_throws("read_pickle", []() { pandas::read_pickle("test.pkl"); });
13852 all_passed &= test_throws("read_sas", []() { pandas::read_sas("test.sas7bdat"); });
13853 all_passed &= test_throws("read_spss", []() { pandas::read_spss("test.sav"); });
13854 all_passed &= test_throws("read_stata", []() { pandas::read_stata("test.dta"); });
13855 all_passed &= test_throws("read_sql", []() { pandas::read_sql("SELECT 1", "conn"); });
13856 all_passed &= test_throws("read_xml", []() { pandas::read_xml("test.xml"); });
13857
13858 if (!all_passed) {
13859 throw std::runtime_error("pd_test_top_level_read_stubs failed");
13860 }
13861
13862 std::cout << " -> tests passed" << std::endl;
13863}
13864
13865// ============================================================================
13866// Set Eng Float Format Test
reconstruct_multiindex_from_levels_codes (pd_test_3_all.cpp:23292)
23282 std::cout << " -> test passed" << std::endl;
23283}
23284
23285void test_reconstruct_multiindex() {
23286 std::cout << "========= reconstruct_multiindex ======================";
23287
23288 std::vector<std::vector<std::string>> levels = {{"a", "b"}, {"x", "y", "z"}};
23289 std::vector<std::vector<int64_t>> codes = {{0, 0, 1}, {0, 1, 2}};
23290 std::vector<std::optional<std::string>> names = {"first", "second"};
23291
23292 pandas::MultiIndex mi = pandas::construct_helpers::reconstruct_multiindex_from_levels_codes(levels, codes, names);
23293
23294 if (mi.size() != 3) throw std::runtime_error("expected size 3, got " + std::to_string(mi.size()));
23295 if (mi.nlevels() != 2) throw std::runtime_error("expected 2 levels");
23296
23297 auto tup0 = mi.get_tuple_str(0);
23298 if (tup0[0] != "a" || tup0[1] != "x") throw std::runtime_error("wrong tuple at 0");
23299 auto tup1 = mi.get_tuple_str(1);
23300 if (tup1[0] != "a" || tup1[1] != "y") throw std::runtime_error("wrong tuple at 1");
23301 auto tup2 = mi.get_tuple_str(2);
23302 if (tup2[0] != "b" || tup2[1] != "z") throw std::runtime_error("wrong tuple at 2");
records_to_dataframe (pd_test_3_all.cpp:22975)
22965 col2.is_numeric = true;
22966 col2.is_int = false;
22967
22968 pandas::construct_helpers::RecordColumn col3;
22969 col3.name = "Z";
22970 col3.string_data = {"a", "b", "c"};
22971 col3.is_numeric = false;
22972 col3.is_int = false;
22973
22974 std::vector<pandas::construct_helpers::RecordColumn> cols = {col1, col2, col3};
22975 pandas::DataFrame df = pandas::construct_helpers::records_to_dataframe<pandas::DataFrame>(cols);
22976
22977 // Check shape
22978 auto sh = df.shape();
22979 if (sh[0] != 3 || sh[1] != 3)
22980 throw std::runtime_error("test_records_to_dataframe: expected shape (3,3), got (" +
22981 std::to_string(sh[0]) + "," + std::to_string(sh[1]) + ")");
22982
22983 // Check int column dtype override
22984 if (df.column_dtype_override("X") != "int64")
22985 throw std::runtime_error("test_records_to_dataframe: column X should have dtype override int64");
repr (pd_test_1_all.cpp:10906)
10896 std::cout << " -> tests passed" << std::endl;
10897}
10898
10899void pd_test_extension_index_repr() {
10900 std::cout << "========= repr =========================";
10901
10902 pandas::CategoricalArray arr({"a", "b", "c"});
10903 // Use ExtensionIndex<CategoricalArray> directly to test base class repr
10904 pandas::ExtensionIndex<pandas::CategoricalArray> idx(arr, "test");
10905
10906 std::string repr_str = idx.repr();
10907
10908 bool passed = (!repr_str.empty() && repr_str.find("ExtensionIndex") != std::string::npos);
10909 if (!passed) {
10910 std::cout << " [FAIL] : in pd_test_extension_index_repr() : repr check failed" << std::endl;
10911 throw std::runtime_error("pd_test_extension_index_repr failed");
10912 }
10913
10914 std::cout << " -> tests passed" << std::endl;
10915}
reset_option (pd_test_3_all.cpp:13407)
13397 // Test set_option
13398 pandas::set_option<int64_t>("display.max_rows", 100);
13399 int64_t new_max_rows = pandas::get_option<int64_t>("display.max_rows");
13400 if (new_max_rows != 100) {
13401 std::cout << " [FAIL] : in pd_test_top_level_options() : set_option failed" << std::endl;
13402 throw std::runtime_error("pd_test_top_level_options failed: set_option");
13403 }
13404
13405 // Test reset_option
13406 pandas::reset_option("display.max_rows");
13407 max_rows = pandas::get_option<int64_t>("display.max_rows");
13408 if (max_rows != 60) {
13409 std::cout << " [FAIL] : in pd_test_top_level_options() : reset_option failed" << std::endl;
13410 throw std::runtime_error("pd_test_top_level_options failed: reset_option");
13411 }
13412
13413 // Test describe_option
13414 std::string desc = pandas::describe_option("display.max_rows");
13415 if (desc.empty() || desc.find("display.max_rows") == std::string::npos) {
13416 std::cout << " [FAIL] : in pd_test_top_level_options() : describe_option empty or missing key" << std::endl;
resolve_result_dtype (pd_test_5_all.cpp:151761)
151751 check_pwc("dtype_resolve_437102_case_62_int8_uint64_widens_f64",
151752 "int8", "uint64", "float64", local_fail);
151753 check_pwc("dtype_resolve_437102_case_62_int64_uint64_widens_f64",
151754 "int64", "uint64", "float64", local_fail);
151755}
151756
151757void f_dtype_resolve_437102_case_63_resolve_result_dtype(int& local_fail) {
151758 std::cout << "-- case_63_resolve_result_dtype\n";
151759 bool threw_empty = false;
151760 try {
151761 (void)pandas::detail::resolve_result_dtype({}, "sum", false);
151762 } catch (const std::invalid_argument&) {
151763 threw_empty = true;
151764 }
151765 pandas_tests::check(threw_empty,
151766 "dtype_resolve_437102_case_63_resolve_empty_throws", local_fail);
151767
151768 bool threw_object_mean = false;
151769 try {
151770 (void)pandas::detail::resolve_result_dtype({"object"}, "mean", false);
151771 } catch (const std::invalid_argument&) {
resolve_series_ctor_target_dtype (pd_test_5_all.cpp:129248)
129238 return h;
129239}
129240
129241static void expect_target(const std::string& tag,
129242 const Hist& hist,
129243 const std::string& src,
129244 const std::string& expected,
129245 int& local_fail) {
129246 std::string out;
129247 try {
129248 out = pandas::resolve_series_ctor_target_dtype(hist, src);
129249 } catch (const std::exception& e) {
129250 std::cout << " exception: " << e.what() << "\n";
129251 out = "<exc>";
129252 }
129253 bool ok = (out == expected);
129254 pandas_tests::check(ok, "resolve_series_ctor_target_dtype_" + tag + "()", local_fail);
129255 if (!ok) {
129256 std::cout << " src=[" << src << "] expected=[" << expected
129257 << "] got=[" << out << "]\n";
129258 }
resolve_string_endpoint_ns (pd_test_3_all.cpp:25267)
25257 dti->set_freq("D");
25258 s.set_index(std::move(dti));
25259 return s;
25260}
25261
25262void pd_test_datetime_range_slice_basic() {
25263 std::cout << "========= slice_by_ns_range basic =======================";
25264 auto s = make_hourly_series(48);
25265 const auto* dti = dynamic_cast<const pandas::DatetimeIndex*>(&s.index());
25266 // Slice to first day: 2013-01-01 00:00 .. 2013-01-01 23:59:59.999999999
25267 int64_t start_ns = pandas::datetime_utils::resolve_string_endpoint_ns("2013-01-01", "left");
25268 int64_t end_ns = pandas::datetime_utils::resolve_string_endpoint_ns("2013-01-01", "right");
25269 auto result = pandas::datetime_utils::slice_by_ns_range(s, *dti, start_ns, end_ns);
25270 if (result.size() != 24) {
25271 std::cout << " [FAIL] : expected 24 entries, got " << result.size() << std::endl;
25272 throw std::runtime_error("slice_by_ns_range basic failed");
25273 }
25274 std::cout << " -> tests passed" << std::endl;
25275}
25276
25277void pd_test_datetime_range_slice_empty() {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
result (pd_test_1_all.cpp:15406)
15396 data.setElementAt({0}, numpy::datetime64(100LL, numpy::DateTimeUnit::Nanosecond));
15397 data.setElementAt({1}, numpy::datetime64(200LL, numpy::DateTimeUnit::Nanosecond));
15398
15399 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
15400 mask.setElementAt({0}, numpy::bool_(false));
15401 mask.setElementAt({1}, numpy::bool_(false));
15402
15403 pandas::DatetimeArray arr(data, mask);
15404 pandas::DatetimeIndexBase idx(arr, "original");
15405
15406 // Create join result (int64 values)
15407 numpy::NDArray<numpy::int64> join_result(std::vector<size_t>{3});
15408 join_result.setElementAt({0}, numpy::int64(500LL));
15409 join_result.setElementAt({1}, numpy::int64(600LL));
15410 join_result.setElementAt({2}, numpy::int64(700LL));
15411
15412 auto new_idx = idx._from_join_target(join_result);
15413
15414 bool passed = (new_idx.size() == 3 &&
15415 new_idx.name().has_value() && *new_idx.name() == "original");
15416 if (!passed) {
round_ns_1000 (pd_test_3_all.cpp:25505)
25495 throw std::runtime_error("classify_value_dtype failed: int32");
25496 if (pandas::classify_value_dtype("Int64[pyarrow]").kind != pandas::ValueKind::IntNullable)
25497 throw std::runtime_error("classify_value_dtype failed: Int64[pyarrow]");
25498 if (pandas::classify_value_dtype("float64").kind != pandas::ValueKind::Float)
25499 throw std::runtime_error("classify_value_dtype failed: float64");
25500
25501 std::cout << " -> tests passed" << std::endl;
25502}
25503
25504void pd_test_value_classify_round_ns() {
25505 std::cout << "========= round_ns_1000() ==============================";
25506 int64_t r = pandas::round_ns_1000(1500000000123456789.0);
25507 if (r % 1000 != 0)
25508 throw std::runtime_error("round_ns_1000 failed: not 1000-aligned");
25509 if (pandas::round_ns_1000(0.0) != 0)
25510 throw std::runtime_error("round_ns_1000 failed: zero");
25511 std::cout << " -> tests passed" << std::endl;
25512}
25513
25514void pd_test_value_classify_whole_numbers() {
25515 std::cout << "========= all_whole_numbers() ==========================";
route_extension_dtype (pd_test_5_all.cpp:40863)
40853namespace f_test_08a_router_9_ns {
40854
40855static void expect_route(const std::string& dtype_label,
40856 const std::string& expected_storage,
40857 const std::string& expected_override,
40858 bool expected_needs_mask,
40859 bool expected_is_index_backed,
40860 const std::string& case_label,
40861 int& local_fail) {
40862 pandas::ExtensionDtypeRouteResult got =
40863 pandas::route_extension_dtype(dtype_label);
40864
40865 pandas_tests::check(got.storage_dtype == expected_storage,
40866 case_label + ".storage_dtype", local_fail);
40867 pandas_tests::check(got.override_label == expected_override,
40868 case_label + ".override_label", local_fail);
40869 pandas_tests::check(got.needs_mask == expected_needs_mask,
40870 case_label + ".needs_mask", local_fail);
40871 pandas_tests::check(got.is_index_backed == expected_is_index_backed,
40872 case_label + ".is_index_backed", local_fail);
40873}
s (pd_test_1_all.cpp:4524)
4514#include <vector>
4515#include "../pandas/pd_dataframe.h"
4516#include "../pandas/pd_series.h"
4517
4518namespace dataframe_tests {
4519 namespace dataframe_tests_aggregation {
4520
4521 void pd_test_aggregation_series_sem() {
4522 std::cout << "========= Series sem ============================";
4523
4524 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
4525 auto sem_val = s.sem();
4526 // std(ddof=1) = sqrt(2.5), sem = sqrt(2.5)/sqrt(5) ≈ 0.707
4527 bool passed = sem_val.has_value() && std::abs(*sem_val - 0.707) < 0.01;
4528 if (!passed) {
4529 std::cout << " [FAIL] : in pd_test_aggregation_series_sem() : sem value incorrect" << std::endl;
4530 throw std::runtime_error("pd_test_aggregation_series_sem failed: sem value incorrect");
4531 }
4532
4533 std::cout << " -> tests passed" << std::endl;
4534 }
s (pd_test_1_all.cpp:4524)
4514#include <vector>
4515#include "../pandas/pd_dataframe.h"
4516#include "../pandas/pd_series.h"
4517
4518namespace dataframe_tests {
4519 namespace dataframe_tests_aggregation {
4520
4521 void pd_test_aggregation_series_sem() {
4522 std::cout << "========= Series sem ============================";
4523
4524 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
4525 auto sem_val = s.sem();
4526 // std(ddof=1) = sqrt(2.5), sem = sqrt(2.5)/sqrt(5) ≈ 0.707
4527 bool passed = sem_val.has_value() && std::abs(*sem_val - 0.707) < 0.01;
4528 if (!passed) {
4529 std::cout << " [FAIL] : in pd_test_aggregation_series_sem() : sem value incorrect" << std::endl;
4530 throw std::runtime_error("pd_test_aggregation_series_sem failed: sem value incorrect");
4531 }
4532
4533 std::cout << " -> tests passed" << std::endl;
4534 }
s (pd_test_1_all.cpp:4524)
4514#include <vector>
4515#include "../pandas/pd_dataframe.h"
4516#include "../pandas/pd_series.h"
4517
4518namespace dataframe_tests {
4519 namespace dataframe_tests_aggregation {
4520
4521 void pd_test_aggregation_series_sem() {
4522 std::cout << "========= Series sem ============================";
4523
4524 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
4525 auto sem_val = s.sem();
4526 // std(ddof=1) = sqrt(2.5), sem = sqrt(2.5)/sqrt(5) ≈ 0.707
4527 bool passed = sem_val.has_value() && std::abs(*sem_val - 0.707) < 0.01;
4528 if (!passed) {
4529 std::cout << " [FAIL] : in pd_test_aggregation_series_sem() : sem value incorrect" << std::endl;
4530 throw std::runtime_error("pd_test_aggregation_series_sem failed: sem value incorrect");
4531 }
4532
4533 std::cout << " -> tests passed" << std::endl;
4534 }
s (pd_test_1_all.cpp:4524)
4514#include <vector>
4515#include "../pandas/pd_dataframe.h"
4516#include "../pandas/pd_series.h"
4517
4518namespace dataframe_tests {
4519 namespace dataframe_tests_aggregation {
4520
4521 void pd_test_aggregation_series_sem() {
4522 std::cout << "========= Series sem ============================";
4523
4524 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
4525 auto sem_val = s.sem();
4526 // std(ddof=1) = sqrt(2.5), sem = sqrt(2.5)/sqrt(5) ≈ 0.707
4527 bool passed = sem_val.has_value() && std::abs(*sem_val - 0.707) < 0.01;
4528 if (!passed) {
4529 std::cout << " [FAIL] : in pd_test_aggregation_series_sem() : sem value incorrect" << std::endl;
4530 throw std::runtime_error("pd_test_aggregation_series_sem failed: sem value incorrect");
4531 }
4532
4533 std::cout << " -> tests passed" << std::endl;
4534 }
select_by_first_level (pd_test_3_all.cpp:26354)
26344void pd_test_multiindex_partial_key_2level() {
26345 std::cout << " Testing select_by_first_level 2-level 'foo'..." << std::endl;
26346 std::vector<std::vector<std::string>> arrays = {
26347 {"foo", "foo", "bar", "bar"},
26348 {"one", "two", "one", "two"}
26349 };
26350 std::vector<std::optional<std::string>> names = {"first", "second"};
26351 auto mi = ::pandas::MultiIndex::from_arrays<std::string>(arrays, names);
26352
26353 auto pk = ::pandas::select_by_first_level(mi,"foo");
26354 if (pk.matched_indices.size() != 2) throw std::runtime_error("Expected 2 matches for 'foo'");
26355 if (pk.matched_indices[0] != 0 || pk.matched_indices[1] != 1) throw std::runtime_error("Wrong indices for 'foo'");
26356 if (!pk.is_single_level()) throw std::runtime_error("Expected single level for 2-level MI");
26357 auto idx = *pk.single_index;
26358 if (idx.size() != 2) throw std::runtime_error("Expected index size 2");
26359 if (idx[0] != "one" || idx[1] != "two") throw std::runtime_error("Wrong index values");
26360 if (!idx.name().has_value() || *idx.name() != "second") throw std::runtime_error("Wrong index name");
26361 std::cout << " PASSED" << std::endl;
26362}
series_from_coo (pd_test_3_all.cpp:25930)
25920#include "../pandas/pd_sparse_accessor.h"
25921
25922void pd_test_sparse_coo_non_dense() {
25923 std::cout << "========= sparse_coo non-dense ========================" << std::endl;
25924 // 3 entries: (0,1)=1.0, (1,2)=2.0, (2,0)=3.0 in a 3x3 matrix
25925 std::vector<double> data = {1.0, 2.0, 3.0};
25926 std::vector<int64_t> rows = {0, 1, 2};
25927 std::vector<int64_t> cols = {1, 2, 0};
25928
25929 auto s = ::pandas::series_from_coo(data, rows, cols, 3, 3, false);
25930 if (s.size() != 3) throw std::runtime_error("Expected 3 entries, got " + std::to_string(s.size()));
25931
25932 // Verify sorted by (row, col): (0,1)=1.0, (1,2)=2.0, (2,0)=3.0
25933 // Already sorted in this case
25934 if (std::abs(static_cast<double>(s.iat(0)) - 1.0) > 1e-10) throw std::runtime_error("Wrong value at 0");
25935 if (std::abs(static_cast<double>(s.iat(1)) - 2.0) > 1e-10) throw std::runtime_error("Wrong value at 1");
25936 if (std::abs(static_cast<double>(s.iat(2)) - 3.0) > 1e-10) throw std::runtime_error("Wrong value at 2");
25937
25938 // Verify has MultiIndex
25939 if (!s.has_multiindex()) throw std::runtime_error("Expected MultiIndex");
series_to_optional_string_vector (pd_test_3_all.cpp:25845)
25835 return dataframe_tests_series_format_helpers::pd_test_series_format_helpers_main();
25836}
25837// ------------------- pd_test_series_format_helpers (end) -----------------------
25838
25839// ------------------- pd_test_cat_constructor_helpers (start) -------------------
25840namespace dataframe_tests_cat_constructor_helpers {
25841
25842void pd_test_cat_constructor_helpers_basic() {
25843 std::cout << "========= cat_constructor_helpers basic =================" << std::endl;
25844 ::pandas::Series<std::string> s(std::vector<std::string>{"a", "b", "c"});
25845 auto result = ::pandas::series_to_optional_string_vector(s);
25846 if (result.size() != 3) throw std::runtime_error("Expected size 3, got " + std::to_string(result.size()));
25847 for (size_t i = 0; i < 3; ++i) {
25848 if (!result[i].has_value()) throw std::runtime_error("Expected value at index " + std::to_string(i));
25849 }
25850 if (result[0].value() != "a") throw std::runtime_error("Expected 'a' at index 0");
25851 if (result[1].value() != "b") throw std::runtime_error("Expected 'b' at index 1");
25852 if (result[2].value() != "c") throw std::runtime_error("Expected 'c' at index 2");
25853 std::cout << " PASSED" << std::endl;
25854}
set_column_resolved (pd_test_5_all.cpp:94241)
94231 pandas::DtypeOverride ov = pandas::DtypeOverride::parse("Float64");
94232 auto df = pandas::from_records_resolved<pandas::DataFrame>(rows, cols, ov);
94233 pandas_tests::check(df.column_dtype_override("n") == "Float64",
94234 "C_26h_case_144_records_override_applies()_dtype", local_fail);
94235}
94236
94237void case_150_create_new_column(int& local_fail) {
94238 std::cout << "-- case_150_create_new_column\n";
94239 pandas::DataFrame df;
94240 KVec col = { kv_int(1), kv_int(2) };
94241 df.set_column_resolved("n", col);
94242 pandas_tests::check(df.has_column("n"),
94243 "C_26h_case_150_create_new_column()_has", local_fail);
94244 pandas_tests::check(df.column_dtype_override("n") == "int64",
94245 "C_26h_case_150_create_new_column()_dtype", local_fail);
94246}
94247
94248void case_151_replace_existing_int_to_float(int& local_fail) {
94249 std::cout << "-- case_151_replace_existing_int_to_float\n";
94250 pandas::DataFrame df;
94251 df.add_column<std::int64_t>("v", { 1, 2, 3 });
set_eng_float_format (pd_test_3_all.cpp:13870)
13860 }
13861
13862 std::cout << " -> tests passed" << std::endl;
13863}
13864
13865// ============================================================================
13866// Set Eng Float Format Test
13867// ============================================================================
13868
13869void pd_test_top_level_set_eng_float_format() {
13870 std::cout << "========= set_eng_float_format() ======================";
13871
13872 // Test set_eng_float_format
13873 pandas::set_eng_float_format(4, true);
13874
13875 int64_t precision = pandas::get_option<int64_t>("display.precision");
13876 if (precision != 4) {
13877 std::cout << " [FAIL] : in pd_test_top_level_set_eng_float_format() : precision not set" << std::endl;
13878 throw std::runtime_error("pd_test_top_level_set_eng_float_format failed: precision");
13879 }
set_max_cols (pd_test_1_all.cpp:970)
960 std::cout << "-> tests passed" << std::endl;
961 }
962
963 void pd_test_config_display_options() {
964 std::cout << "========= df_config: display options ======================= ";
965 pandas::DataFrameConfig::set_max_rows(100);
966 if (pandas::DataFrameConfig::get_max_rows() != 100) {
967 std::cout << "[FAIL] : in pd_test_config_display_options() : set_max_rows failed" << std::endl;
968 throw std::runtime_error("pd_test_config_display_options failed: set_max_rows failed");
969 }
970 pandas::DataFrameConfig::set_max_cols(50);
971 if (pandas::DataFrameConfig::get_max_cols() != 50) {
972 std::cout << "[FAIL] : in pd_test_config_display_options() : set_max_cols failed" << std::endl;
973 throw std::runtime_error("pd_test_config_display_options failed: set_max_cols failed");
974 }
975 std::cout << "-> tests passed" << std::endl;
976 }
977
978} // namespace dataframe_tests_config
979
980int pd_test_config_main() {
set_max_rows (pd_test_1_all.cpp:965)
955 pandas::DataFrameConfig::set_na_repr("<NA>");
956 if (std::string(pandas::DataFrameConfig::get_na_repr()) != "<NA>") {
957 std::cout << "[FAIL] : in pd_test_config_na_repr() : set_na_repr failed" << std::endl;
958 throw std::runtime_error("pd_test_config_na_repr failed: set_na_repr failed");
959 }
960 std::cout << "-> tests passed" << std::endl;
961 }
962
963 void pd_test_config_display_options() {
964 std::cout << "========= df_config: display options ======================= ";
965 pandas::DataFrameConfig::set_max_rows(100);
966 if (pandas::DataFrameConfig::get_max_rows() != 100) {
967 std::cout << "[FAIL] : in pd_test_config_display_options() : set_max_rows failed" << std::endl;
968 throw std::runtime_error("pd_test_config_display_options failed: set_max_rows failed");
969 }
970 pandas::DataFrameConfig::set_max_cols(50);
971 if (pandas::DataFrameConfig::get_max_cols() != 50) {
972 std::cout << "[FAIL] : in pd_test_config_display_options() : set_max_cols failed" << std::endl;
973 throw std::runtime_error("pd_test_config_display_options failed: set_max_cols failed");
974 }
975 std::cout << "-> tests passed" << std::endl;
set_multiindex_with_tuple_labels (pd_test_3_all.cpp:23338)
23328 std::cout << "========= set_multiindex_with_tuple_labels ============";
23329
23330 std::vector<std::vector<std::string>> arrays = {{"a", "a", "b"}, {"x", "y", "x"}};
23331 pandas::MultiIndex mi = pandas::MultiIndex::from_arrays<std::string>(arrays, {});
23332
23333 std::map<std::string, std::vector<double>> data = {
23334 {"col1", {1.0, 2.0, 3.0}}
23335 };
23336 pandas::DataFrame df(data);
23337
23338 pandas::construct_helpers::set_multiindex_with_tuple_labels(df, std::move(mi));
23339
23340 // Verify index has tab-separated labels
23341 const auto& idx = df.index();
23342 std::string lbl0 = idx.get_value_str(0);
23343 std::string lbl1 = idx.get_value_str(1);
23344 std::string lbl2 = idx.get_value_str(2);
23345 if (lbl0 != "a\tx") throw std::runtime_error("wrong label 0: " + lbl0);
23346 if (lbl1 != "a\ty") throw std::runtime_error("wrong label 1: " + lbl1);
23347 if (lbl2 != "b\tx") throw std::runtime_error("wrong label 2: " + lbl2);
set_na_repr (pd_test_1_all.cpp:955)
945 std::cout << "-> tests passed" << std::endl;
946 }
947
948 void pd_test_config_na_repr() {
949 std::cout << "========= df_config: NA representation ======================= ";
950 const char* na_repr = pandas::DataFrameConfig::get_na_repr();
951 if (na_repr == nullptr) {
952 std::cout << "[FAIL] : in pd_test_config_na_repr() : na_repr is null" << std::endl;
953 throw std::runtime_error("pd_test_config_na_repr failed: na_repr is null");
954 }
955 pandas::DataFrameConfig::set_na_repr("<NA>");
956 if (std::string(pandas::DataFrameConfig::get_na_repr()) != "<NA>") {
957 std::cout << "[FAIL] : in pd_test_config_na_repr() : set_na_repr failed" << std::endl;
958 throw std::runtime_error("pd_test_config_na_repr failed: set_na_repr failed");
959 }
960 std::cout << "-> tests passed" << std::endl;
961 }
962
963 void pd_test_config_display_options() {
964 std::cout << "========= df_config: display options ======================= ";
965 pandas::DataFrameConfig::set_max_rows(100);
set_option (pd_test_3_all.cpp:10876)
10866 df.set_multiindex(mi);
10867 auto result = df.reorder_levels({"second", "first"});
10868 if (result.nrows() != 4) {
10869 std::cout << " [FAIL] : in pd_test_3_all_reorder_levels_initlist() : wrong nrows" << std::endl;
10870 throw std::runtime_error("pd_test_3_all_reorder_levels_initlist failed");
10871 }
10872 std::cout << " -> tests passed" << std::endl;
10873}
10874
10875void pd_test_3_all_set_option_instance() {
10876 std::cout << "========= DataFrame.set_option() instance ==============";
10877 pandas::DataFrame df;
10878 df.add_column<int64_t>("A", {1, 2, 3});
10879 df.set_option("display.multi_sparse", false);
10880 df.set_option("display.unknown_key", true); // should not throw
10881 std::cout << " -> tests passed" << std::endl;
10882}
10883
10884// ============================================================================
10885// Category 48: Indexing Fixes (Plan: plan_indexing_fixes)
10886// ============================================================================
set_option (pd_test_3_all.cpp:10876)
10866 df.set_multiindex(mi);
10867 auto result = df.reorder_levels({"second", "first"});
10868 if (result.nrows() != 4) {
10869 std::cout << " [FAIL] : in pd_test_3_all_reorder_levels_initlist() : wrong nrows" << std::endl;
10870 throw std::runtime_error("pd_test_3_all_reorder_levels_initlist failed");
10871 }
10872 std::cout << " -> tests passed" << std::endl;
10873}
10874
10875void pd_test_3_all_set_option_instance() {
10876 std::cout << "========= DataFrame.set_option() instance ==============";
10877 pandas::DataFrame df;
10878 df.add_column<int64_t>("A", {1, 2, 3});
10879 df.set_option("display.multi_sparse", false);
10880 df.set_option("display.unknown_key", true); // should not throw
10881 std::cout << " -> tests passed" << std::endl;
10882}
10883
10884// ============================================================================
10885// Category 48: Indexing Fixes (Plan: plan_indexing_fixes)
10886// ============================================================================
set_option (pd_test_3_all.cpp:10876)
10866 df.set_multiindex(mi);
10867 auto result = df.reorder_levels({"second", "first"});
10868 if (result.nrows() != 4) {
10869 std::cout << " [FAIL] : in pd_test_3_all_reorder_levels_initlist() : wrong nrows" << std::endl;
10870 throw std::runtime_error("pd_test_3_all_reorder_levels_initlist failed");
10871 }
10872 std::cout << " -> tests passed" << std::endl;
10873}
10874
10875void pd_test_3_all_set_option_instance() {
10876 std::cout << "========= DataFrame.set_option() instance ==============";
10877 pandas::DataFrame df;
10878 df.add_column<int64_t>("A", {1, 2, 3});
10879 df.set_option("display.multi_sparse", false);
10880 df.set_option("display.unknown_key", true); // should not throw
10881 std::cout << " -> tests passed" << std::endl;
10882}
10883
10884// ============================================================================
10885// Category 48: Indexing Fixes (Plan: plan_indexing_fixes)
10886// ============================================================================
set_option (pd_test_3_all.cpp:10876)
10866 df.set_multiindex(mi);
10867 auto result = df.reorder_levels({"second", "first"});
10868 if (result.nrows() != 4) {
10869 std::cout << " [FAIL] : in pd_test_3_all_reorder_levels_initlist() : wrong nrows" << std::endl;
10870 throw std::runtime_error("pd_test_3_all_reorder_levels_initlist failed");
10871 }
10872 std::cout << " -> tests passed" << std::endl;
10873}
10874
10875void pd_test_3_all_set_option_instance() {
10876 std::cout << "========= DataFrame.set_option() instance ==============";
10877 pandas::DataFrame df;
10878 df.add_column<int64_t>("A", {1, 2, 3});
10879 df.set_option("display.multi_sparse", false);
10880 df.set_option("display.unknown_key", true); // should not throw
10881 std::cout << " -> tests passed" << std::endl;
10882}
10883
10884// ============================================================================
10885// Category 48: Indexing Fixes (Plan: plan_indexing_fixes)
10886// ============================================================================
setup_time_rolling (pd_test_3_all.cpp:24692)
24682 std::vector<numpy::datetime64> dates = {
24683 numpy::datetime64("2023-01-01"),
24684 numpy::datetime64("2023-01-02"),
24685 numpy::datetime64("2023-01-03"),
24686 numpy::datetime64("2023-01-04"),
24687 numpy::datetime64("2023-01-05")
24688 };
24689 auto dti = std::make_unique<pandas::DatetimeIndex>(dates);
24690 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
24691 s.set_index(std::move(dti));
24692 auto rolling = pandas::setup_time_rolling(s, "3D", "right", 1);
24693 if (!rolling.is_time_based())
24694 throw std::runtime_error("expected time-based rolling");
24695 std::cout << " -> tests passed" << std::endl;
24696}
24697
24698void pd_test_rolling_time_no_dti() {
24699 std::cout << "========= setup_time_rolling no DTI =================";
24700 // Series without DatetimeIndex should throw
24701 pandas::Series<double> s({1.0, 2.0, 3.0});
24702 bool threw = false;
show_versions (pd_test_3_all.cpp:13805)
13795 }
13796
13797 std::cout << " -> tests passed" << std::endl;
13798}
13799
13800// ============================================================================
13801// Show Versions Test
13802// ============================================================================
13803
13804void pd_test_top_level_show_versions() {
13805 std::cout << "========= show_versions() =============================";
13806
13807 std::string versions = pandas::show_versions();
13808
13809 if (versions.empty()) {
13810 std::cout << " [FAIL] : in pd_test_top_level_show_versions() : empty output" << std::endl;
13811 throw std::runtime_error("pd_test_top_level_show_versions failed: empty");
13812 }
13813
13814 if (versions.find("pandas-cpp") == std::string::npos) {
13815 std::cout << " [FAIL] : in pd_test_top_level_show_versions() : missing pandas-cpp" << std::endl;
slice_by_ns_range (pd_test_3_all.cpp:25269)
25259 return s;
25260}
25261
25262void pd_test_datetime_range_slice_basic() {
25263 std::cout << "========= slice_by_ns_range basic =======================";
25264 auto s = make_hourly_series(48);
25265 const auto* dti = dynamic_cast<const pandas::DatetimeIndex*>(&s.index());
25266 // Slice to first day: 2013-01-01 00:00 .. 2013-01-01 23:59:59.999999999
25267 int64_t start_ns = pandas::datetime_utils::resolve_string_endpoint_ns("2013-01-01", "left");
25268 int64_t end_ns = pandas::datetime_utils::resolve_string_endpoint_ns("2013-01-01", "right");
25269 auto result = pandas::datetime_utils::slice_by_ns_range(s, *dti, start_ns, end_ns);
25270 if (result.size() != 24) {
25271 std::cout << " [FAIL] : expected 24 entries, got " << result.size() << std::endl;
25272 throw std::runtime_error("slice_by_ns_range basic failed");
25273 }
25274 std::cout << " -> tests passed" << std::endl;
25275}
25276
25277void pd_test_datetime_range_slice_empty() {
25278 std::cout << "========= slice_by_ns_range empty =======================";
25279 auto s = make_hourly_series(48);
sparsify_labels (pd_test_3_all.cpp:25706)
25696 }
25697 std::cout << " -> tests passed" << std::endl;
25698}
25699
25700void pd_test_display_formats_sparsify() {
25701 std::cout << "========= display::sparsify_labels =====================";
25702 std::vector<std::vector<std::string>> levels = {
25703 {"A", "A", "B"},
25704 {"x", "y", "x"}
25705 };
25706 auto result = ::pandas::display::sparsify_labels(levels);
25707 if (result[0][0] != "A" || result[0][1] != "" || result[0][2] != "B") {
25708 throw std::runtime_error("sparsify outer level failed");
25709 }
25710 if (result[1][0] != "x" || result[1][1] != "y" || result[1][2] != "x") {
25711 throw std::runtime_error("sparsify inner level failed");
25712 }
25713 std::cout << " -> tests passed" << std::endl;
25714}
25715
25716void pd_test_display_formats_sparsify_single() {
ss (pd_test_3_all.cpp:27670)
27660 fail++;
27661 } else {
27662 auto cats = str_s->get_cat_categories();
27663 if (cats.size() != 3) {
27664 std::cout << " FAIL: expected 3 categories, got " << cats.size() << std::endl;
27665 fail++;
27666 }
27667 }
27668 }
27669
27670 pandas::Series<std::string> ss({"a", "b", "a", "c"}, "strs");
27671 auto result2 = ss.astype("category");
27672 auto* str_s2 = dynamic_cast<pandas::Series<std::string>*>(result2.get());
27673 if (!str_s2) {
27674 std::cout << " FAIL: expected Series<string> for string->category" << std::endl;
27675 fail++;
27676 } else {
27677 if (str_s2->dtype_name() != "category") {
27678 std::cout << " FAIL: dtype should be category" << std::endl;
27679 fail++;
27680 }
ss (pd_test_3_all.cpp:27670)
27660 fail++;
27661 } else {
27662 auto cats = str_s->get_cat_categories();
27663 if (cats.size() != 3) {
27664 std::cout << " FAIL: expected 3 categories, got " << cats.size() << std::endl;
27665 fail++;
27666 }
27667 }
27668 }
27669
27670 pandas::Series<std::string> ss({"a", "b", "a", "c"}, "strs");
27671 auto result2 = ss.astype("category");
27672 auto* str_s2 = dynamic_cast<pandas::Series<std::string>*>(result2.get());
27673 if (!str_s2) {
27674 std::cout << " FAIL: expected Series<string> for string->category" << std::endl;
27675 fail++;
27676 } else {
27677 if (str_s2->dtype_name() != "category") {
27678 std::cout << " FAIL: dtype should be category" << std::endl;
27679 fail++;
27680 }
ss (pd_test_3_all.cpp:27670)
27660 fail++;
27661 } else {
27662 auto cats = str_s->get_cat_categories();
27663 if (cats.size() != 3) {
27664 std::cout << " FAIL: expected 3 categories, got " << cats.size() << std::endl;
27665 fail++;
27666 }
27667 }
27668 }
27669
27670 pandas::Series<std::string> ss({"a", "b", "a", "c"}, "strs");
27671 auto result2 = ss.astype("category");
27672 auto* str_s2 = dynamic_cast<pandas::Series<std::string>*>(result2.get());
27673 if (!str_s2) {
27674 std::cout << " FAIL: expected Series<string> for string->category" << std::endl;
27675 fail++;
27676 } else {
27677 if (str_s2->dtype_name() != "category") {
27678 std::cout << " FAIL: dtype should be category" << std::endl;
27679 fail++;
27680 }
ss (pd_test_3_all.cpp:27670)
27660 fail++;
27661 } else {
27662 auto cats = str_s->get_cat_categories();
27663 if (cats.size() != 3) {
27664 std::cout << " FAIL: expected 3 categories, got " << cats.size() << std::endl;
27665 fail++;
27666 }
27667 }
27668 }
27669
27670 pandas::Series<std::string> ss({"a", "b", "a", "c"}, "strs");
27671 auto result2 = ss.astype("category");
27672 auto* str_s2 = dynamic_cast<pandas::Series<std::string>*>(result2.get());
27673 if (!str_s2) {
27674 std::cout << " FAIL: expected Series<string> for string->category" << std::endl;
27675 fail++;
27676 } else {
27677 if (str_s2->dtype_name() != "category") {
27678 std::cout << " FAIL: dtype should be category" << std::endl;
27679 fail++;
27680 }
ss (pd_test_3_all.cpp:27670)
27660 fail++;
27661 } else {
27662 auto cats = str_s->get_cat_categories();
27663 if (cats.size() != 3) {
27664 std::cout << " FAIL: expected 3 categories, got " << cats.size() << std::endl;
27665 fail++;
27666 }
27667 }
27668 }
27669
27670 pandas::Series<std::string> ss({"a", "b", "a", "c"}, "strs");
27671 auto result2 = ss.astype("category");
27672 auto* str_s2 = dynamic_cast<pandas::Series<std::string>*>(result2.get());
27673 if (!str_s2) {
27674 std::cout << " FAIL: expected Series<string> for string->category" << std::endl;
27675 fail++;
27676 } else {
27677 if (str_s2->dtype_name() != "category") {
27678 std::cout << " FAIL: dtype should be category" << std::endl;
27679 fail++;
27680 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
static_assert (pd_test_3_all.cpp:1503)
1493 }
1494
1495 std::cout << " -> tests passed" << std::endl;
1496}
1497
1498void pd_test_3_all_pandas_numpy_type_aliases() {
1499 std::cout << "========= pandas:: aliases for numpy time types =====";
1500
1501 // Case A: pandas::Timestamp == pandas::Timestamp (same type)
1502 {
1503 static_assert(std::is_same_v<pandas::Timestamp, pandas::Timestamp>,
1504 "pandas::Timestamp must alias pandas::Timestamp");
1505 pandas::Timestamp ts1("2021-01-01");
1506 pandas::Timestamp ts2("2021-01-01");
1507 // Stronger than toString()-comparison: pandas::Timestamp::operator==
1508 // compares the underlying nanosecond value directly, catching
1509 // representation drift that string formatting could mask.
1510 if (!(ts1 == ts2)) {
1511 throw std::runtime_error("alias Timestamp: ctor value mismatch");
1512 }
1513 }
store (pd_test_3_all.cpp:19223)
19213#include <cstdio>
19214
19215namespace dataframe_tests {
19216namespace dataframe_tests_hdf5_real {
19217
19218void test_write_read_1d() {
19219 std::string path = "test_hdf5_real.h5";
19220
19221 // Write
19222 {
19223 pandas::HDF5Store store(path, "w");
19224 std::vector<double> data = {1.0, 2.0, 3.0, 4.0, 5.0};
19225 store.write_dataset("my_data", data);
19226 }
19227
19228 // Read
19229 {
19230 pandas::HDF5Store store(path, "r");
19231 auto result = store.read_dataset<double>("my_data");
19232 if (result.size() != 5)
19233 throw std::runtime_error("test_write_read_1d: size mismatch");
store (pd_test_3_all.cpp:19223)
19213#include <cstdio>
19214
19215namespace dataframe_tests {
19216namespace dataframe_tests_hdf5_real {
19217
19218void test_write_read_1d() {
19219 std::string path = "test_hdf5_real.h5";
19220
19221 // Write
19222 {
19223 pandas::HDF5Store store(path, "w");
19224 std::vector<double> data = {1.0, 2.0, 3.0, 4.0, 5.0};
19225 store.write_dataset("my_data", data);
19226 }
19227
19228 // Read
19229 {
19230 pandas::HDF5Store store(path, "r");
19231 auto result = store.read_dataset<double>("my_data");
19232 if (result.size() != 5)
19233 throw std::runtime_error("test_write_read_1d: size mismatch");
style (pd_test_2_all.cpp:9128)
9118 std::cout << "====================================== [OK] pd_test_reorder_levels test suite ========================== " << std::endl;
9119 return 0;
9120 }
9121
9122} // namespace dataframe_tests
9123// ------------------- pd_test_reorder_levels.cpp (end) -----------------------------
9124
9125// ------------------- pd_test_styler.cpp (start) -----------------------------
9126// dataframe_tests/pd_test_styler.cpp
9127// Test suite for DataFrame.style() and Styler class functionality
9128
9129#include <iostream>
9130#include <sstream>
9131#include <string>
9132#include <vector>
9133#include <map>
9134#include "../pandas/pd_dataframe.h"
9135
9136// CRITICAL: No using namespace directives
td (pd_test_1_all.cpp:9535)
9525 }
9526
9527 std::cout << " -> tests passed" << std::endl;
9528}
9529
9530void pd_test_timedelta_rounding_params() {
9531 std::cout << "========= Timedelta rounding with DST params =====";
9532
9533 // Create a Timedelta: 1h 30m 45s
9534 // Constructor is: (days, hours, minutes, seconds, ...)
9535 pandas::Timedelta td(0, 1, 30, 45); // 0 days, 1h, 30m, 45s
9536
9537 // Test floor with ambiguous/nonexistent params
9538 pandas::Timedelta floored = td.floor("h", "raise", "raise");
9539 std::cout << std::endl << " floor('h'): " << floored.toString();
9540
9541 // Test ceil with ambiguous/nonexistent params
9542 pandas::Timedelta ceiled = td.ceil("h", "raise", "raise");
9543 std::cout << std::endl << " ceil('h'): " << ceiled.toString();
9544
9545 // Test round with ambiguous/nonexistent params
td (pd_test_1_all.cpp:9535)
9525 }
9526
9527 std::cout << " -> tests passed" << std::endl;
9528}
9529
9530void pd_test_timedelta_rounding_params() {
9531 std::cout << "========= Timedelta rounding with DST params =====";
9532
9533 // Create a Timedelta: 1h 30m 45s
9534 // Constructor is: (days, hours, minutes, seconds, ...)
9535 pandas::Timedelta td(0, 1, 30, 45); // 0 days, 1h, 30m, 45s
9536
9537 // Test floor with ambiguous/nonexistent params
9538 pandas::Timedelta floored = td.floor("h", "raise", "raise");
9539 std::cout << std::endl << " floor('h'): " << floored.toString();
9540
9541 // Test ceil with ambiguous/nonexistent params
9542 pandas::Timedelta ceiled = td.ceil("h", "raise", "raise");
9543 std::cout << std::endl << " ceil('h'): " << ceiled.toString();
9544
9545 // Test round with ambiguous/nonexistent params
time_unit_factor (pd_test_3_all.cpp:22752)
22742 return dataframe_tests_concat_axis0_dtype_preserve::pd_test_concat_axis0_dtype_preserve_main();
22743}
22744// ------------------- pd_test_concat_axis0_dtype_preserve.cpp (end) ---------------------------
22745
22746// ------------------- pd_test_df_construct_time_dtype (start) ---------------------------
22747namespace dataframe_tests_df_construct_time_dtype {
22748
22749void test_time_unit_factor() {
22750 std::cout << " test_time_unit_factor" << std::endl;
22751
22752 if (pandas::construct_helpers::time_unit_factor(numpy::DateTimeUnit::Nanosecond) != 1LL)
22753 throw std::runtime_error("test_time_unit_factor: Nanosecond factor wrong");
22754 if (pandas::construct_helpers::time_unit_factor(numpy::DateTimeUnit::Microsecond) != 1000LL)
22755 throw std::runtime_error("test_time_unit_factor: Microsecond factor wrong");
22756 if (pandas::construct_helpers::time_unit_factor(numpy::DateTimeUnit::Millisecond) != 1000000LL)
22757 throw std::runtime_error("test_time_unit_factor: Millisecond factor wrong");
22758 if (pandas::construct_helpers::time_unit_factor(numpy::DateTimeUnit::Second) != 1000000000LL)
22759 throw std::runtime_error("test_time_unit_factor: Second factor wrong");
22760 if (pandas::construct_helpers::time_unit_factor(numpy::DateTimeUnit::Minute) != 60000000000LL)
22761 throw std::runtime_error("test_time_unit_factor: Minute factor wrong");
22762 if (pandas::construct_helpers::time_unit_factor(numpy::DateTimeUnit::Hour) != 3600000000000LL)
timedelta64_to_ns (pd_test_3_all.cpp:22799)
22789 throw std::runtime_error("test_datetime64_to_ns: 2 ns should be 2 ns, got " + std::to_string(ns_ns));
22790
22791 std::cout << " -> test passed" << std::endl;
22792}
22793
22794void test_timedelta64_to_ns() {
22795 std::cout << " test_timedelta64_to_ns" << std::endl;
22796
22797 // 3 milliseconds = 3000000 nanoseconds
22798 numpy::timedelta64 td_ms(3, numpy::DateTimeUnit::Millisecond);
22799 int64_t ns_ms = pandas::construct_helpers::timedelta64_to_ns(td_ms);
22800 if (ns_ms != 3000000LL)
22801 throw std::runtime_error("test_timedelta64_to_ns: 3 ms should be 3000000 ns, got " + std::to_string(ns_ms));
22802
22803 // 2 hours = 7200000000000 nanoseconds
22804 numpy::timedelta64 td_h(2, numpy::DateTimeUnit::Hour);
22805 int64_t ns_h = pandas::construct_helpers::timedelta64_to_ns(td_h);
22806 if (ns_h != 7200000000000LL)
22807 throw std::runtime_error("test_timedelta64_to_ns: 2 h should be 7200000000000 ns, got " + std::to_string(ns_h));
22808
22809 std::cout << " -> test passed" << std::endl;
timedelta_range (pd_test_1_all.cpp:20049)
20039 }
20040
20041 std::cout << " -> tests passed" << std::endl;
20042}
20043
20044// ============================================================================
20045// Factory Function Tests
20046// ============================================================================
20047
20048void pd_test_timedelta_index_timedelta_range_start_end() {
20049 std::cout << "========= timedelta_range (start, end) ================";
20050
20051 auto idx = pandas::timedelta_range("0 days", "9 days");
20052
20053 bool passed = (idx.size() == 10);
20054 if (!passed) {
20055 std::cout << " [FAIL] : expected 10 elements, got " << idx.size() << std::endl;
20056 throw std::runtime_error("pd_test_timedelta_index_timedelta_range_start_end failed");
20057 }
20058
20059 std::cout << " -> tests passed" << std::endl;
trim (pd_test_5_all.cpp:58873)
58863 auto trim = [](const std::string& s) {
58864 size_t a = s.find_first_not_of(" \t");
58865 size_t b = s.find_last_not_of(" \t\r");
58866 if (a == std::string::npos) return std::string();
58867 return s.substr(a, b - a + 1);
58868 };
58869 size_t pos = 0;
58870 while (pos < body.size()) {
58871 size_t nl = body.find('\n', pos);
58872 std::string raw = body.substr(pos, nl == std::string::npos ? std::string::npos : nl - pos);
58873 std::string t = trim(raw);
58874 if (!t.empty()) {
58875 // tokenise by whitespace
58876 std::vector<std::string> toks;
58877 std::string cur;
58878 for (char c : t) {
58879 if (c == ' ' || c == '\t') {
58880 if (!cur.empty()) { toks.push_back(cur); cur.clear(); }
58881 } else {
58882 cur.push_back(c);
58883 }
ts (pd_test_2_all.cpp:22590)
22580void test_to_datetime_numeric_seconds() {
22581 std::cout << " -- test_to_datetime_numeric_seconds --" << std::endl;
22582 // 1490195805 seconds = 2017-03-22 15:16:45 UTC
22583 std::vector<double> vals = {1490195805.0};
22584 auto arr = pandas::to_datetime_numeric(vals, "s");
22585 check(arr.size() == 1, "size==1");
22586 auto v = arr[0];
22587 check(v.has_value(), "has_value");
22588 if (v.has_value()) {
22589 pandas::Timestamp ts(v->getValue());
22590 check(ts.year() == 2017, "year==2017");
22591 check(ts.month() == 3, "month==3");
22592 check(ts.day() == 22, "day==22");
22593 check(ts.hour() == 15, "hour==15");
22594 check(ts.minute() == 16, "min==16");
22595 check(ts.second() == 45, "sec==45");
22596 }
22597}
22598
22599void test_to_datetime_numeric_millis() {
ts (pd_test_2_all.cpp:22590)
22580void test_to_datetime_numeric_seconds() {
22581 std::cout << " -- test_to_datetime_numeric_seconds --" << std::endl;
22582 // 1490195805 seconds = 2017-03-22 15:16:45 UTC
22583 std::vector<double> vals = {1490195805.0};
22584 auto arr = pandas::to_datetime_numeric(vals, "s");
22585 check(arr.size() == 1, "size==1");
22586 auto v = arr[0];
22587 check(v.has_value(), "has_value");
22588 if (v.has_value()) {
22589 pandas::Timestamp ts(v->getValue());
22590 check(ts.year() == 2017, "year==2017");
22591 check(ts.month() == 3, "month==3");
22592 check(ts.day() == 22, "day==22");
22593 check(ts.hour() == 15, "hour==15");
22594 check(ts.minute() == 16, "min==16");
22595 check(ts.second() == 45, "sec==45");
22596 }
22597}
22598
22599void test_to_datetime_numeric_millis() {
ts (pd_test_2_all.cpp:22590)
22580void test_to_datetime_numeric_seconds() {
22581 std::cout << " -- test_to_datetime_numeric_seconds --" << std::endl;
22582 // 1490195805 seconds = 2017-03-22 15:16:45 UTC
22583 std::vector<double> vals = {1490195805.0};
22584 auto arr = pandas::to_datetime_numeric(vals, "s");
22585 check(arr.size() == 1, "size==1");
22586 auto v = arr[0];
22587 check(v.has_value(), "has_value");
22588 if (v.has_value()) {
22589 pandas::Timestamp ts(v->getValue());
22590 check(ts.year() == 2017, "year==2017");
22591 check(ts.month() == 3, "month==3");
22592 check(ts.day() == 22, "day==22");
22593 check(ts.hour() == 15, "hour==15");
22594 check(ts.minute() == 16, "min==16");
22595 check(ts.second() == 45, "sec==45");
22596 }
22597}
22598
22599void test_to_datetime_numeric_millis() {
undefined_variable (pd_test_5_all.cpp:72243)
72233 check_eq_str(
72234 "case_3.cat6_dtype.cannot_cast",
72235 "Cannot cast float64 to int64",
72236 pandas::error_messages::cannot_cast("float64", "int64"),
72237 local_fail);
72238
72239 // Category 7: UndefinedVariableError (eval/query).
72240 check_eq_str(
72241 "case_3.cat7_UndefinedVariable.undefined_variable",
72242 "name 'x' is not defined",
72243 pandas::error_messages::undefined_variable("x"),
72244 local_fail);
72245
72246 // Category 8: UnsortedIndexError — MultiIndex lexsort.
72247 check_eq_str(
72248 "case_3.cat8_UnsortedIndex.unsorted_index",
72249 "Key length (3) was greater than MultiIndex lexsort depth",
72250 pandas::error_messages::unsorted_index("3"),
72251 local_fail);
72252}
undefined_variable_in_query (pd_test_5_all.cpp:73753)
73743 [[maybe_unused]] auto h4 = pandas::error_messages::cannot_cast("a", "b");
73744 ++helpers_seen;
73745 [[maybe_unused]] auto h5 = pandas::error_messages::undefined_variable("x");
73746 ++helpers_seen;
73747 [[maybe_unused]] auto h6 = pandas::error_messages::unsorted_index("3");
73748 ++helpers_seen;
73749 [[maybe_unused]] auto h7 =
73750 pandas::error_messages::unsorted_index_key_vs_depth(2, 0);
73751 ++helpers_seen;
73752 [[maybe_unused]] auto h8 =
73753 pandas::error_messages::undefined_variable_in_query("x");
73754 ++helpers_seen;
73755
73756 constexpr size_t kExpectedFixedLowerBound = 2;
73757 constexpr size_t kExpectedHelperLowerBound = 8;
73758 constexpr size_t kPush3RegistryTotalLowerBound = 83;
73759
73760 pandas_tests::check(fixed_seen >= kExpectedFixedLowerBound,
73761 "case_1.fixed_cardinality_at_least_lower_bound",
73762 local_fail);
73763 pandas_tests::check(helpers_seen >= kExpectedHelperLowerBound,
unit_string_to_ns_multiplier (pd_test_5_all.cpp:51448)
51438 }
51439 std::cout << " -> tests passed" << std::endl;
51440}
51441
51442// --- f_test_marshal_na_smoke_9.cpp ---
51443
51444namespace f_test_marshal_na_smoke_9_ns {
51445
51446void case_1_unit_empty_default_ns(int& local_fail) {
51447 std::cout << "-- case_1_unit_empty_default_ns\n";
51448 int64_t m = pandas::unit_string_to_ns_multiplier("", pandas::UnitDefault::Nanoseconds);
51449 pandas_tests::check(m == 1, "case_1.empty_with_Nanoseconds_default_is_1", local_fail);
51450}
51451
51452void case_2_unit_empty_default_seconds(int& local_fail) {
51453 std::cout << "-- case_2_unit_empty_default_seconds\n";
51454 int64_t m = pandas::unit_string_to_ns_multiplier("", pandas::UnitDefault::Seconds);
51455 pandas_tests::check(m == 1000000000LL, "case_2.empty_with_Seconds_default_is_1e9", local_fail);
51456}
51457
51458void case_3_unit_ms(int& local_fail) {
unknown_interpolation_method (pd_test_5_all.cpp:75473)
75463 pandas_tests::check(is_pure_ascii(pandas::error_messages::kData2D),
75464 "case_3.kData2D_ascii", local_fail);
75465 pandas_tests::check(is_pure_ascii(pandas::error_messages::kColumnLengthMismatch),
75466 "case_3.kColumnLengthMismatch_ascii", local_fail);
75467 pandas_tests::check(is_pure_ascii(pandas::error_messages::kSampleWeightsLength),
75468 "case_3.kSampleWeightsLength_ascii", local_fail);
75469 pandas_tests::check(
75470 is_pure_ascii(pandas::error_messages::length_mismatch_columns(3, 5)),
75471 "case_3.length_mismatch_columns_ascii", local_fail);
75472 pandas_tests::check(
75473 is_pure_ascii(pandas::error_messages::unknown_interpolation_method("foo")),
75474 "case_3.unknown_interpolation_method_ascii", local_fail);
75475}
75476
75477void case_4_no_trailing_whitespace(int& local_fail) {
75478 std::cout << "-- case_4_no_trailing_whitespace\n";
75479 pandas_tests::check(has_no_trailing_ws(pandas::error_messages::kQuantileQOutOfRange),
75480 "case_4.kQuantileQOutOfRange_no_trail", local_fail);
75481 pandas_tests::check(has_no_trailing_ws(pandas::error_messages::kStepCannotBeZero),
75482 "case_4.kStepCannotBeZero_no_trail", local_fail);
75483 pandas_tests::check(has_no_trailing_ws(pandas::error_messages::kInclusiveInvalid),
unsorted_index (pd_test_5_all.cpp:72250)
72240 check_eq_str(
72241 "case_3.cat7_UndefinedVariable.undefined_variable",
72242 "name 'x' is not defined",
72243 pandas::error_messages::undefined_variable("x"),
72244 local_fail);
72245
72246 // Category 8: UnsortedIndexError — MultiIndex lexsort.
72247 check_eq_str(
72248 "case_3.cat8_UnsortedIndex.unsorted_index",
72249 "Key length (3) was greater than MultiIndex lexsort depth",
72250 pandas::error_messages::unsorted_index("3"),
72251 local_fail);
72252}
72253
72254void case_4_label_not_found_format(int& local_fail) {
72255 std::cout << "-- case_4_label_not_found_format\n";
72256 check_eq_str("case_4.label_not_found_foo",
72257 "[foo] not in index",
72258 pandas::error_messages::label_not_found("foo"),
72259 local_fail);
72260 check_eq_str("case_4.label_not_found_bar_baz",
unsorted_index_key_vs_depth (pd_test_5_all.cpp:73447)
73437 pandas_tests::check(expected == actual,
73438 "case_5.undefined_variable_byte_exact",
73439 local_fail);
73440}
73441
73442void case_6_unsorted_index_key_vs_depth(int& local_fail) {
73443 std::cout << "-- case_6_unsorted_index_key_vs_depth\n";
73444 const std::string expected =
73445 "Key length (2) was greater than MultiIndex lexsort depth (0)";
73446 const std::string actual =
73447 pandas::error_messages::unsorted_index_key_vs_depth(2, 0);
73448 pandas_tests::check(expected == actual,
73449 "case_6.unsorted_index_key_vs_depth_byte_exact",
73450 local_fail);
73451}
73452
73453} // namespace f_test_error_messages_registry_ns
73454
73455void f_test_error_messages_registry() {
73456 std::cout << "========= f_test_error_messages_registry =======";
73457 int local_fail = 0;
unsupported_binop (pd_test_5_all.cpp:74704)
74694 static_assert(
74695 std::is_same_v<decltype(pandas::error_messages::numeric_only_false_sum_hint(std::string{})),
74696 std::string>,
74697 "numeric_only_false_sum_hint must return std::string");
74698 static_assert(
74699 std::is_same_v<decltype(pandas::error_messages::cannot_compare_types(std::string{},
74700 std::string{})),
74701 std::string>,
74702 "cannot_compare_types must return std::string");
74703 static_assert(
74704 std::is_same_v<decltype(pandas::error_messages::unsupported_binop(std::string{},
74705 std::string{},
74706 std::string{})),
74707 std::string>,
74708 "unsupported_binop must return std::string");
74709
74710 pandas_tests::check(true, "case_1.cat5_constants_and_helpers_type_pinned",
74711 local_fail);
74712}
74713
74714void case_2_byte_exact_wording(int& local_fail) {
unsupported_dtype (pd_test_5_all.cpp:74120)
74110 "kCannotConvertNaNToBool must be const std::string_view");
74111 static_assert(std::is_same_v<decltype(pandas::error_messages::kCannotConvertNullableIntegerToBool),
74112 const std::string_view>,
74113 "kCannotConvertNullableIntegerToBool must be const std::string_view");
74114
74115 constexpr std::string_view k = pandas::error_messages::kCannotConvertNAToInteger;
74116 static_assert(k.size() > 0, "kCannotConvertNAToInteger must have content");
74117
74118 // Format helpers exist and return std::string.
74119 static_assert(
74120 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype(std::string{})),
74121 std::string>,
74122 "unsupported_dtype must return std::string");
74123 static_assert(
74124 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_quoted(std::string{},
74125 std::string{})),
74126 std::string>,
74127 "unsupported_dtype_quoted must return std::string");
74128 static_assert(
74129 std::is_same_v<decltype(pandas::error_messages::cannot_astype_convert(std::string{},
74130 std::string{})),
unsupported_dtype_for_multiindex (pd_test_5_all.cpp:74139)
74129 std::is_same_v<decltype(pandas::error_messages::cannot_astype_convert(std::string{},
74130 std::string{})),
74131 std::string>,
74132 "cannot_astype_convert must return std::string");
74133 static_assert(
74134 std::is_same_v<decltype(pandas::error_messages::cannot_convert_index_to_dtype(std::string{},
74135 std::string{})),
74136 std::string>,
74137 "cannot_convert_index_to_dtype must return std::string");
74138 static_assert(
74139 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_for_multiindex(std::string{})),
74140 std::string>,
74141 "unsupported_dtype_for_multiindex must return std::string");
74142 static_assert(
74143 std::is_same_v<decltype(pandas::error_messages::cannot_convert_value_in_column(
74144 std::string{}, std::string{}, std::string{}, std::size_t{0}, std::string{})),
74145 std::string>,
74146 "cannot_convert_value_in_column must return std::string");
74147
74148 pandas_tests::check(true, "case_1.cat6_constants_and_helpers_type_pinned",
74149 local_fail);
unsupported_dtype_quoted (pd_test_5_all.cpp:74124)
74114 constexpr std::string_view k = pandas::error_messages::kCannotConvertNAToInteger;
74115 static_assert(k.size() > 0, "kCannotConvertNAToInteger must have content");
74116
74117 // Format helpers exist and return std::string.
74118 static_assert(
74119 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype(std::string{})),
74120 std::string>,
74121 "unsupported_dtype must return std::string");
74122 static_assert(
74123 std::is_same_v<decltype(pandas::error_messages::unsupported_dtype_quoted(std::string{},
74124 std::string{})),
74125 std::string>,
74126 "unsupported_dtype_quoted must return std::string");
74127 static_assert(
74128 std::is_same_v<decltype(pandas::error_messages::cannot_astype_convert(std::string{},
74129 std::string{})),
74130 std::string>,
74131 "cannot_astype_convert must return std::string");
74132 static_assert(
74133 std::is_same_v<decltype(pandas::error_messages::cannot_convert_index_to_dtype(std::string{},
unsupported_op (pd_test_5_all.cpp:72229)
72219 check_eq_str(
72220 "case_3.cat4_ValueError.length_mismatch",
72221 "Length of values (3) does not match length of index (5)",
72222 pandas::error_messages::length_mismatch("values", 3, "index", 5),
72223 local_fail);
72224
72225 // Category 5: TypeError — unsupported op.
72226 check_eq_str(
72227 "case_3.cat5_TypeError.unsupported_op",
72228 "unsupported operand type for +: 'object'",
72229 pandas::error_messages::unsupported_op("+", "object"),
72230 local_fail);
72231
72232 // Category 6: dtype — cannot cast.
72233 check_eq_str(
72234 "case_3.cat6_dtype.cannot_cast",
72235 "Cannot cast float64 to int64",
72236 pandas::error_messages::cannot_cast("float64", "int64"),
72237 local_fail);
72238
72239 // Category 7: UndefinedVariableError (eval/query).
version (pd_test_1_all.cpp:940)
930#include <stdexcept>
931
932#include "../pandas/pd_config.h"
933
934namespace dataframe_tests {
935
936namespace dataframe_tests_config {
937
938 void pd_test_config_version() {
939 std::cout << "========= df_config: version info ======================= ";
940 const char* version = pandas::DataFrameInfo::version();
941 if (version == nullptr || std::string(version).empty()) {
942 std::cout << "[FAIL] : in pd_test_config_version() : version is null or empty" << std::endl;
943 throw std::runtime_error("pd_test_config_version failed: version is null or empty");
944 }
945 std::cout << "-> tests passed" << std::endl;
946 }
947
948 void pd_test_config_na_repr() {
949 std::cout << "========= df_config: NA representation ======================= ";
950 const char* na_repr = pandas::DataFrameConfig::get_na_repr();
wide_to_long (pd_test_3_all.cpp:9311)
9301 // Original: 2 rows, reshape with 2 periods -> 4 rows
9302 if (result.nrows() != 4) {
9303 std::cout << " [FAIL] : in pd_test_3_all_lreshape() : expected 4 rows, got " << result.nrows() << std::endl;
9304 throw std::runtime_error("pd_test_3_all_lreshape failed: nrows");
9305 }
9306
9307 std::cout << " -> tests passed" << std::endl;
9308}
9309
9310void pd_test_3_all_wide_to_long() {
9311 std::cout << "========= wide_to_long() ==========================";
9312
9313 // Create wide-format panel data
9314 std::map<std::string, std::vector<double>> data = {
9315 {"id", {1.0, 2.0}},
9316 {"A1", {10.0, 20.0}},
9317 {"A2", {11.0, 21.0}},
9318 {"B1", {100.0, 200.0}},
9319 {"B2", {101.0, 201.0}}
9320 };
9321 pandas::DataFrame df(data);